[antlr-interest] brief analysis of java.g's tree building in 2.x
vs proposed 3.0
Terence Parr
parrt at cs.usfca.edu
Thu Feb 3 17:15:27 PST 2005
On Feb 1, 2005, at 2:06 AM, Dean Tribble wrote:
> Incidentally, in your examples below, I don't understand why you don't
> use the ## shortcut to refer to the current node when comparing new and
> old syntaxes. For example,
>
>> modifiers
>> : ( modifier )*
>> {#modifiers = #([MODIFIERS, "MODIFIERS"], #modifiers);}
>> ;
>
> should be
> modifiers
> : ( modifier )*
> {##= #([MODIFIERS, "MODIFIERS"], ##);}
> ;
Yeah, that's cool. Just a style thing I guess.
> A particular thing I wanted to be able to do is to say "for the node in
> which you recognize "if", make the node of type IfExpr, but I had to
> explicitly either set the type or create a new parent node.
Yes, this is annoying. There are about 30 of these in the Java grammar
I think.
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. ;)
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