[antlr-interest] Re: Tree weirdness C++ mode

lgcraymer lgc at mail1.jpl.nasa.gov
Thu Apr 29 13:12:39 PDT 2004


--- In antlr-interest at yahoogroups.com, Monty Zukowski <monty at c...> wrote:
> In a parser with C++ as a target, building a tree the following way 
> does not work:
> 
>   ##->addChild(#[EMPTY,"empty"]);
> 
> Instead I have do to this:
> 
> astFactory->addASTChild(currentAST, #[EMPTY,"empty"]);
> 
> If I use addChild() then I see that the root node is updated with the 
> child but some other bookkeeping must be happening because it gets 
> overwritten later.
> 
> This contradicts some of the information in here: 
> http://wwwhome.cs.utwente.nl/~klaren/antlr/treebuilding.txt
> 
> Anybody know what's going on?

Yes--the normal tree building mechanism uses an ASTPair (currentAST;
thest have the structure { root, lastChild }.  The ASTFactory version
of addASTChild updates the "lastChild" field, while the AST version
does not.

> Also doing ##=#(##,#[EMPTY,"empty"]); seems to overwrite the first 
> child--equivalent to addFirstChild().  I always thought it would be 
> equivalent to addChild().  So the following two have different 
> behaviors:
> 
> astFactory->addASTChild(currentAST, #[EMPTY]);
> ##=#(##,#[EMPTY,"empty"]);
> 
> Does that seem right?  I suspect this might be different from Java.

Java is the same, and it does make sense from the internals.  It gives
the user optimization control by leaving the construction operators
fairly dumb.  My construction stuff will help a bit (2.8; I'm still
waiting for release approval), but we will need to revisit the tree
construction internals for ANTLR 3 to make use a bit less error-prone.

--Loring

> Discovered in version 2.7.2.  Also present in 2.7.3 and 2.7.4rc1.
> 
> Monty



 
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