Reputation: 4633
I am using the ^ and ! operators to set the root node and to not not be included in the AST, respectively. However, it is not making a difference in the tree that is generated by ANTLRWorks. So I am not sure if my grammar is incorrect or if ANTLRWorks just isn't creating a correct tree.
Here is an snippet of my grammar
expr
: '('! logExpr ')'!;
These parenthesis should not be included in the AST.
addExpr
: multExpr ( (PLUS|MINUS)^ multExpr )*;
The PLUS or MINUS should be the root node in the AST.
However neither of these things are happening the way I expect them to. It makes no difference when I remove them or put them back. ANTLRWorks 1.4.3 ANTLR 3.4
Upvotes: 2
Views: 440
Reputation: 170178
ANTLRWorks' interpreter shows the parse tree, even though you've put output=AST;
in the grammar's options-block, as you already found yourself.
However, ANTLRWorks' debugger does show the AST. To activate the debugger, press CTL+D or select Run->
Debug from the menu bar.
The debugger is able to visualize the parse tree and AST. Note that it will not handle embedded code other than Java.
Upvotes: 4
Reputation: 4633
I found the answer. ANTLRWorks shows the parse tree, not the AST. It ignores all rewrites. This led to my second question which was, how do I visualize the AST if ANTLRWorks doesn't do it for me? The answer for that is found here.
Upvotes: 2