[antlr-interest] (...)+ rules do not throw NoViableAltException

Erik Kratochvil discontinuum at gmail.com
Fri Jan 25 08:09:16 PST 2008


Consider the following grammar

grammar E;

prog:   (stat)+ ;

stat:   'define' ID '=' INT ';'   |   'declare' ID ';'   ;

ID  :   ('a'..'z'|'A'..'Z')+ ;
INT :   '0'..'9'+ ;
WS  :   (' '|'\t'|'\n'|'\r')+ {skip();} ;


For the *prog* rule org.antlr.Tool E.g (antlr-3.0.1) gives

public final void prog() throws RecognitionException {
...
            int cnt1=0;
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==7||LA1_0==10) ) {
                    alt1=1;
                }

                switch (alt1) {
            	case 1 :
...
            	default :
            	    if ( cnt1 >= 1 ) break loop1;
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        throw eee;
                }
                cnt1++;
            } while (true);
...
}



I think that the grammar generator should place an else clause right after

if ( (LA1_0==7||LA1_0==10) ) {
   alt1=1;
}

that throws NoViableAltException.


-- 
Erik Kratochvil


More information about the antlr-interest mailing list