[antlr-interest] Re: Non-determinism when k==2

Gokhan Caglar gcaglar at gmail.com
Wed Mar 15 13:48:58 PST 2006


> The nondeterminism warning comes from "linear approximate lookahead".
> Antlr may still generate the right code. if so you can either shutdown
> the warning or workaround the grammar(left factor).

Antlr is not generating the right code in this case,

The first one is wrong:
                                   do {
                                               if
((LA(1)==DO||LA(1)==BREAK) && (_tokenSet_1.member(LA(2)))) {
                                                           statement();
                                               }
                                               else {
                                                           break _loop6;
                                               }
                                   } while (true);

The second one is right:
                                               if ((LA(1)==DO) &&
(LA(2)==THIS)) {
                                                           statement1();
                                               }
                                               else if ((LA(1)==BREAK)) {
                                                           statement3();
                                               }
                                               else {
                                                           break _loop6;
                                               }
                                   } while (true);

The only difference is saying ( (statement1 | statement3) )* vs.
saying (statement1 | statement3)

Thanks,
Gokhan


More information about the antlr-interest mailing list