[antlr-interest] Re: Transforming AST subtrees in TreeParser with "buildAST = false"

micheal_jor open.zone at virgin.net
Wed May 19 13:20:17 PDT 2004


--- In antlr-interest at yahoogroups.com, Ric Klaren <klaren at c...> wrote:
> On Wed, May 19, 2004 at 02:45:52PM -0000, micheal_jor wrote:
> > Is this possible?
> 
> To some extent it should work I guess. (I'm btw also in a kindoff
similar
> situation where I only want to do some minor patching in a previously
> generated tree. I'm not that familiar with tree transformations but it
> feels a bit cumbersome atm)

I went ahead and wrote the code anyways and it works as expected. The
XXX_AST_in variable continues to point to whatever it pointed to on
entry but the AST was properly modified.

Cumbersome?. Perhaps, I'm much more concerned about performance as it
happens. Flexible it definitely is though. I've got custom AST node
classes, custom ASTFactory, custom token class, custom buffers, etc
and it still all works.

> > I am using a TreeParser but with buildAST=false to avoid redundant
> > "copying" of most of the nodes in the AST. They are untouched by the
> > minor transformations.
> >
> > I guess I have two questions really:
> >
> > 1. In a TreeParser, is it possible to specify that "buildAST=true"
> > only for certain rules or rule-Alternatives. The rest of the AST is
> > left as is (it is "copied" to output logically but no *actual* copying
> > is done).
> 
> buildAST is a grammar option so no go there... Doing it inverted
will work
> e.g. turn on construction and disable construction for all rules
except the
> ones where you want it.

I didn't think of that (sound like much work).

> Also you have to be very carefull when changing the
> AST because the current rule is operating on it still.

I do the transforming after all the recognition is complete.

> Also be very carefull in using
> the standard AST/ASTFactory's methods for changing tree parts, the names
> hide a lot of things that happen under the hood...

Yeah gave up pretty quickly on using ASTPair/ASTFactory directly.
Might go back a little later just to grok the difference.

> I guess you could come a long way with playing a bit with a toy
grammar and
> the options and see what happens in the generated code.

Was under a little time pressure so just bit the bullet. I've got the
SCC trail in case anything bad hapens anyhows  ;-)

Cheers,

Micheal




 
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