[antlr-interest] Serious Bug when using BitSetgeneration-Forgot

Terence Parr parrt at cs.usfca.edu
Sat Nov 5 17:02:04 PST 2005


> Hopefully we can find a solution to this "Empty Pruction & BitSet  
> wrong
> code generation".
>
> It has kept my puzzling about errors in my grammar for a long long  
> time,
> but I have put off investigating it because there had been other more
> important things to look at. However, I know had to solve it, and it
> turned out to be a Bug !

Hi.  Here is my test case:

class T extends Parser;

x : A|C|D|E|F|G|H;

s : a b ;

// here is the rule of interest
a : B
   | {p1}? ( )
   | {p2}? ( )
   ;

b : A|D|F|G|H;

All is well.  It generates the following for rule a:

             if ((LA(1)==B)) {
                 match(B);
             }
             else if (((_tokenSet_1.member(LA(1))))&&(p1)) {
                 {
                 }
             }
             else if (((_tokenSet_1.member(LA(1))))&&(p2)) {
                 {
                 }
             }

clearly the bitsets are there.  Can you nail your bug down to a  
simple grammar like this that fails?

I realized that ANTLR will not (as I said in last email) delete the  
lookahead; it's smart enough to know that the predicates are only  
valid in the right context and so it keeps the lookahead the same.

Thanks,
Ter


More information about the antlr-interest mailing list