[antlr-interest] Differences between ANTLR3 and ANTLR2
tree-building operators
A.J. Admiraal
news at admiraal.dds.nl
Wed Jan 25 08:00:09 PST 2006
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)
However when I do a similar thing in ANTLR2:
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)
It seems the ANTLR3 ^^ operator takes note of the parentheses so the C^^
takes the first B with it. Is this behavior intentional, or can it be
classified as a bug?
Another related question is how should these two operators work when
nested? For example when I do this:
A^^ ((B C^^) D^)
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?
Thanks in advance,
Alex
More information about the antlr-interest
mailing list