What does ^ and ! stand for in ANTLR grammar

时光怂恿深爱的人放手 提交于 2019-12-07 05:04:31

问题


I was having difficulty figuring out what does ^ and ! stand for in ANTLR grammar terminology.


回答1:


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.



来源:https://stackoverflow.com/questions/3466418/what-does-and-stand-for-in-antlr-grammar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!