[antlr-interest] brief analysis of java.g's tree building in 2.x vs proposed 3.0

Loring Craymer Loring.G.Craymer at jpl.nasa.gov
Thu Feb 3 17:49:50 PST 2005


At 05:15 PM 2/3/2005, Terence Parr wrote:
I am thinking like this MAYBE:

>ifStat : IF^[IFEXPR] '('! expr ')'! stat ... ;
>
>where IF becomes a root and the type becomes IFEXPR.  I don't like this as 
>it's not very clear.  I would prefer in this case:
>
>ifStat : IF '(' expr ')' stat -> ^(IFEXPR expr stat) ;
>
>using the 3.0 proposed syntax.  Verbose as hell compared to ^ but very 
>clear ;)  Can anybody think of a good syntax for the "change my token 
>type" functionality?
>
>Heh, what if we used -> like this:
>
>ifStat : (IF->IFEXPR) '('! expr ')'! stat ... ;
>
>Then it begs the question: can I allow a tree rewrite not just a token 
>type change on a single node?  Nah...then I would really be getting 
>complicated. ;)

This gets pretty ghastly.  You need an attribute syntax, with nodes having 
default attributes "text" and "type".  Then something like
IF  @IF.type = IFEXPR
might make sense.


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




More information about the antlr-interest mailing list