开发者

What does ^ and ! stand for in ANTLR grammar

开发者 https://www.devze.com 2023-01-11 11:31 出处:网络
I was开发者_开发技巧 having difficulty figuring out what does ^ and ! stand for in ANTLR grammar terminology.Have a look at the ANTLR Cheat Sheet:

I was开发者_开发技巧 having difficulty figuring out what does ^ and ! stand for in ANTLR grammar terminology.


Have a look at the ANTLR Cheat Sheet:

! don't include in AST
^ make AST root node

And ^ can also be used in rewrite rules: ... -> ^( ... ). For example, the following two parser rules are equivalent:

expression
  :  A '+'^ A ';'!
  ;

and:

expression
  :  A '+' A ';' -> ^('+' A A)
  ;

Both create the following AST:

  +
 / \
A   A

In other words: the + is made as root, the two A's its children, and the ; is omitted from the tree.

0

精彩评论

暂无评论...
验证码 换一张
取 消