...
To be written. Volunteers?
Java | Code Block |
---|
grammar Simple;SimpleCalc;
tokens {
PLUS = '+' ;
MINUS = '-' ;
MULT = '*' ;
DIV = '/' ;
}
@header {
//package antlr3.tutorial.simple;
}
@lexer::header {
//package antlr3.tutorial.simple;
}
@members {
public static void main(String[] args) throws Exception {
SimpleCalcLexer lex = new SimpleCalcLexer(new ANTLRFileStream(args[0]));
CommonTokenStream tokens = new CommonTokenStream(lex);
SimpleCalc parser = new SimpleCalc(tokens);
try {
parser.expr();
} catch (RecognitionException e) {
e.printStackTrace();
}
OR : '||' ;
}
}
}
/*------------------------------------------------------------------
* PARSER RULES
*------------------------------------------------------------------*/
expr : term ( ( PLUS | MINUS ) term )*
;
term : factor ( ( MULT | DIV ) factor )*
;
factor : NUMBER
;
/*------------------------------------------------------------------
* LEXER RULES
*------------------------------------------------------------------*/
NUMBER : (DIGIT)+
;
WHITESPACE
: ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { channel = 99; }
;
fragment
DIGIT : '0'..'9'
; |
|
---|
C# | Code Block |
---|
grammar SimpleSimpleCalc;
options
{
language=CSharp;
}
OR : '||' tokens {
PLUS = '+' ;
MINUS = '-' ;
MULT = '*' ;
DIV = '/' ;
}
@header {
//package antlr3.tutorial.simple;
}
@lexer::header {
//package antlr3.tutorial.simple;
}
@members {
public static void Main(string[] args) {
SimpleCalcLexer lex = new SimpleCalcLexer(new ANTLRFileStream(args[0]));
CommonTokenStream tokens = new CommonTokenStream(lex);
SimpleCalc parser = new SimpleCalc(tokens);
try {
parser.expr();
} catch (RecognitionException e) {
Console.Error.WriteLine(e.StackTrace);
}
}
}
/*------------------------------------------------------------------
* PARSER RULES
*------------------------------------------------------------------*/
expr : term ( ( PLUS | MINUS ) term )*
;
term : factor ( ( MULT | DIV ) factor )*
;
factor : NUMBER
;
/*------------------------------------------------------------------
* LEXER RULES
*------------------------------------------------------------------*/
NUMBER : (DIGIT)+
;
WHITESPACE
: ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { channel = 99; }
;
fragment
DIGIT : '0'..'9'
;
|
|
---|
Objective-C | Code Block |
---|
grammar Simple;
options
{
language=ObjC;
}
OR : '||' ;
|
|
---|
C | Code Block |
---|
grammar Simple;
options
{
language=C;
}
OR : '||' ;
|
|
---|
...