[antlr-interest] Jump over nodes in tree construction

marc schellens m_schellens at hotmail.com
Mon Mar 14 22:11:08 PST 2005


>From: Terence Parr <parrt at cs.usfca.edu>
>To: ANTLR Interest <antlr-interest at antlr.org>
>Subject: Re: [antlr-interest] Jump over nodes in tree construction
>Date: Mon, 14 Mar 2005 14:33:55 -0800
>
>
>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;
>}


Thanks Terence,

I figured it out: #( ...,  ex->getFirstChild())  (same for #ex->...) is 
translated to  ex->...  NOT  ex_AST->...
in C++ mode, so one has to put here #(..., ex_AST->...)  explicitely.
But I think your way might be better anyway.

marc




More information about the antlr-interest mailing list