Dear ANTLR users! (developers?)

I have a very basic problem: supposed I have two rules, one which 
basically includes any token, and another one that contains only a 
subset of them, say:

any : A | B | C | D ;
some
    : A B
    | B
    ;

Now, I want to combine those two rules:

rule     : ( options{ greedy=false;} : any )+ some      ;

.. such that the inner loop should consume any's, as long as LA(1)!=B && 
(LA(1)!=A||LA(2)!=B). This should be easily recognizable by the parser 
(in my opinion). However, ANTLR 3 (3.1.2) says:

warning: Decision can match input such as "A B" using multiple 
alternatives: 1, 2

Note that when I change the rule "some" to:

some : A | B;

such that only a lookahead of one character is enough, everything works 
as expected: "any" is consumed until a character is found from the 
difference "any-some".

Now, I thought "ok, use backtracking". Enabling it globally seems to 
work. But, if I try to enable it only locally, it does not seem to have 
any effect. Actually, I tried to enable it for any rule in my grammar - 
without any effect! (I include the grammar in question as attachement)

What can I do? Thanks for any hints!
Andreas Meyer

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

grammar GreedyTest;
//options
//{
        // backtrack = true;
//}

start
// options { backtrack = true; }
    : rule EOF;

rule 
// options { backtrack = true; }
        : ( options{ greedy=false;} : any )+ some 
    ;

any
// options { backtrack = true; }
        : A 
        | B 
        | C 
        | D 
        ;

some
// options { backtrack = true; }
        // : A // this works fine.
        : A B // this does not. why? the lookaheadset is the same: {A,B}. 
        | B
        ;

A: 'A';
B: 'B';
C: 'C';
D: 'D';
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to