[antlr-interest] Re: building instruction/ASTnode pairs

lgcraymer lgc at mail1.jpl.nasa.gov
Sun Nov 14 10:18:18 PST 2004



--- In antlr-interest at yahoogroups.com, Terence Parr <parrt at c...> wrote:
> Loring spake:
> 
> >> Arrays, besides being memory hogs, do not address the root cause of 
> >> the
> >> cyclic reference problem.  The cyclic reference problem is due to the
> >> current brute force tree construction algorithm; a better
approach is 
> >> to
> >> build a stream of instruction/payload pairs and then construct the 
> >> tree
> >> after all instructions have been gathered.
> >
> john mitchell spake:
> 
> > Yes, the cyclic reference problem is crucial to deal with cleanly.  
> > Antlr's
> > existing model of tree (re-)construction is brittle.  A linguistic 
> > approach
> > (create stream of instructions, sort & unique'ify, and apply) is both 
> > more
> > powerful and simpler.
> 
> Loring or John.  May i have a simple example (rule + pseudo-actions or 
> whatever) that explains more precisely about what you intend?  I 
> understand the concept; TokenStreamRewriteEngine does not actually 
> modify the token buffer, it tracks a list of "instructions" that are 
> carried out when you say "toString()".

There is a full implementation of the concept in the 2.8 code--take a
look at JavaCodeGenerator.interpretTreeAction (the instruction
interpreter), TreeActionElement (the instruction stream), and
TreeCodeBlock (single instruction plus data).  antlr.g plus
NewMakeGrammar has code that sets the instruction stream.  There is
about 100 LOC total.  The only additional feature needed for ANTLR 3
is to reset the instruction stream; I did not need that for tree
action construction.  The version there uses ASTPair, but that was
done to fit with the existing AST construction in ANTLR 2.

--Loring

> Ter
> --
> CS Professor & Grad Director, University of San Francisco
> Creator, ANTLR Parser Generator, http://www.antlr.org
> Cofounder, http://www.jguru.com
> Cofounder, http://www.knowspam.net enjoy email again!





 
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