[antlr-interest] Jump over nodes in tree construction
Terence Parr
parrt at cs.usfca.edu
Mon Mar 14 14:33:55 PST 2005
On Mar 14, 2005, at 6:06 AM, marc schellens wrote:
> Hello,
>
> could somebody please point out to me what is wrong with the following
> rule?
> Ie. How to skip nodes in the output tree properly?
>
> unbrace_expr!
> : ex:expr
> {
> // remove last pair of braces
> if( #ex->getType()==EXPR)
> #unbrace_expr= #( NULL, ex->getFirstChild());
> else
> #unbrace_expr= #( NULL, ex);
> }
Hi Marc :)
I assume you have set buildAST=true in the tree grammar?
Try referencing #ex not ex.
You can do this with the following by the way:
if ( ... ) {
#unbrace_expr = #ex->getFirstChild();
}
else {
#unbrace_expr = #ex;
}
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
More information about the antlr-interest
mailing list