[antlr-interest] Differences between ANTLR3 and ANTLR2 tree-building operators

Terence Parr parrt at cs.usfca.edu
Thu Jan 26 14:10:13 PST 2006


On Jan 25, 2006, at 8:00 AM, A.J. Admiraal wrote:

> Hi,
>
> I'm checking out some differences between ANTLR3 and ANTLR2  
> regarding the
> tree-building operators. I've read the blog on trees
> (http://www.antlr.org/blog/antlr3/trees.tml) and if I understand it
> correctly, the ANTLR3 ^^ operator should behave exactly as the  
> ANTLR2 ^
> operator. I've done some experiments with the early access release  
> from
> December (ea7), but it seems there is a slight difference.
>
> When I build a rule like this in ANTLR3:
> A^^ (B C^^ D)+
>
> And feed it with:
> A B C D B C D
>
> I get the following ast:
> (C (C A B D) B D)

That looks like a bug to me. :(  Thanks...added to list.

> Another related question is how should these two operators work when
> nested? For example when I do this:
> A^^ ((B C^^) D^)

i assume you have + on that loop...

> And feed it with:
> A B C D B C D
>
> I get:
> (C (C A (D B))(D B))
>
> Is this the correct behavior, or should it be different?

Ack.  Good question.  What is the "root of the current subtree" when  
D^ occurs?    Crap.  I think that it makes no sense to mix ^^ and ^,  
but I wonder what the proper thing to do is.  Should we make it  
illegal to mix?  Just subrules?  Hmm...

For now, can you use the -> notation?  Works much better, in general  
though for trees of unlimited height you usually need the operators.

Ter


More information about the antlr-interest mailing list