[antlr-interest] rewrite rule element cardinality
Terence Parr
parrt at cs.usfca.edu
Tue Feb 23 12:11:48 PST 2010
Hi Joe, this looks like a bug to me!! yikes. You are correct that you should see only one copy of the tree returned by option for each iteration of the tree constructor in search. grr! ok, I will add a bug. Can you do me a favor and look at the generated code for -> ^(GROUP c option)+?? It might tell you something that will help me fix the bug and also a way for you to get around.
Thanks!
T
On Feb 23, 2010, at 11:40 AM, joestelmach at gmail.com wrote:
> I'm having some trouble understanding the behavior of AST rewrite rule element cardinality in certain cases. Consider the following grammar:
>
> grammar Test;
>
> options {
> output=AST;
> }
>
> tokens {
> GROUP;
> FOO;
> BAR;
> BAZ;
> }
>
> search
> : c (SPACE option)+ -> ^(GROUP c option)+
> ;
>
> c
> : C -> FOO BAR
> ;
>
> option
> : (A | B) -> BAZ
> ;
>
> A : 'a';
> B : 'b';
> C : 'c';
> SPACE : ' ';
>
> If we feed the parser the input string: "c a b a", I'm expecting to see the following AST:
>
> (GROUP FOO BAR BAZ) (GROUP FOO BAR BAZ) (GROUP FOO BAR BAZ)
>
> but instead, I get the following:
>
> (GROUP FOO BAR BAZ) (GROUP FOO BAR BAZ BAZ) (GROUP FOO BAR BAZ BAZ)
>
> Notice the extra BAZ in each child after the first? Can someone explain why this is happening? I'm using ANTLR 3.2 with the java target.
>
> Thanks
>
> - Joe
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list