[antlr-interest] Tree-building problem ...

Monty Zukowski monty at codetransform.com
Wed Jun 9 21:48:44 PDT 2004


Your actions are creating nodes but you are not adding them to the  
tree.  They don't get added in automatically like parsed tokens do.

So, for instance, instead of {#[NUMBER_LITERAL,"1"];} you need  
something like {astFactory->addASTChild(currentAST,  
#[NUMBER_LITERAL,"1"]);} (in C++ mode)

Monty

On Jun 8, 2004, at 7:45 AM, Anthony Youngman wrote:

> I'm trying to build a tree. Problem is, I'm trying to create tokens in
> the parser, and can't see how to do it. Here's my parser code ...
>
> //printst : ( PRINT^ (expr (COLON)? )? );
> printst :
> //	( PRINT! {#[IDENT,"!PRINT"]; #[LPAREN, "("];} (expr (COLON!
> {#[NUMBER_LITERAL,"1"];})? )? )
> 	( PRINT! {#printst = #[IDENT,"!PRINT"], #[LPAREN, "("];} (expr
> (COLON! {#[NUMBER_LITERAL,"1"];})? )? )
> 	{ ## = #(#[FUNCTIONCALL,"function-call"], ##); }
> 	;
>
> The first, commented out, version simply returned a root of "PRINT"  
> with
> "expr" and "COLON" as its children. My second attempt - the second
> commented out line, returns the required root of FUNCTIONCALL, but it
> only has one child, namely "expr".
>
> What I'm trying to do is return a tree who's root is FUNCTIONCALL and
> which has, as a minimum, the children "!PRINT", "(" and ")" (and yes,
> I've just realised I've forgotten the ")"). It should also have the
> children "expr" and "1" if they exist.
>
> Cheers,
> Wol
>
>
> *********************************************************************** 
> *****
>
> This transmission is intended for the named recipient only. It may  
> contain private and confidential information. If this has come to you  
> in error you must not act on anything disclosed in it, nor must you  
> copy it, modify it, disseminate it in any way, or show it to anyone.  
> Please e-mail the sender to inform us of the transmission error or  
> telephone ECA International immediately and delete the e-mail from  
> your information system.
>
> Telephone numbers for ECA International offices are: Sydney +61 (0)2  
> 8272 5300, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and  
> New York +1 212 582 2333.
>
> *********************************************************************** 
> *****
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
Monty Zukowski

ANTLR & Java Consultant -- http://www.codetransform.com
ANSI C/GCC transformation toolkit --  
http://www.codetransform.com/gcc.html
Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list