Introduction to ANTLR Jin Tianxing 5110309085
What ANTLR do All ANTLR need is a grammar file where the syntactic rule is defined. The output of ANTLR is a Lexer and a Parser written with Java.
About Versions ANTLR 3.5 ANTLR 4 Tree-rewrite enabled(AST) No GUI Interface to display trees ANTLR 4 Tree-rewrite disabled(Parsing tree) GUI Interface
Grammar grammar example; prog: (expr NEWLINE)* ; expr: INT (OP expr)? NEWLINE: ('\r' | '\n')+; INT: ('0'..'9')+; OP: '+' | '-' | '*' | '/'; However, using this grammar still produce a Parsing Tree.
Tree-Rewrite(ANTLR 3.x) Option: output=AST Different ways of Rewrite: expr: INT (OP^ expr); expr: INT (OP expr) -> ^(OP INT expr); expr: ‘(‘! expr^ ‘)’!; ANTLR 4.x does not support rewrite