What does ^ u! stand in the grammar of ANTLR

It was hard for me to understand what is and what! in the terminology of ANTLR.

+4
source share
1 answer

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.

+8
source

All Articles