Check out the ANTLR Cheat Sheet :
! do not include AST
^ make root AST node
And ^ can also be used in rewrite rules: ... -> ^( ... ) . For example, the following two parsing rules are equivalent:
expression : A '+'^ A ';'! ;
and
expression : A '+' A ';' -> ^('+' AA) ;
Both create the following AST:
+ / \ AA
In other words: + is done as root, its two children are A , a ; lowered out of wood.
source share