[antlr-interest] Again simple nondeterminism problems

John B. Brodie jbb at acm.org
Tue Aug 23 07:36:35 PDT 2005


Greetings!

On Tue, 23 Aug 2005 01:08:48, Ersin Er asked:
>I'll be glad if you can help me about the following nondeterminism
>problems:
>
>OID: NUMERICOID | DESCR;
>NUMERICOID: NUMBER (DOT NUMBER)+;
>NUMBER: DIGIT | ( LDIGIT ( DIGIT )+ );
>protected DOT: '.';
>protected DIGIT: '0' | LDIGIT;
>protected LDIGIT: '1'..'9';
>protected DESCR: ALPHA ( ALPHA | DIGIT | '-' )*;
>protected ALPHA: 'A'..'Z' | 'a'..'z';
>
>and I have literal rules like in the lexer:
>ID_AND: "and";
>ID_OR: "or";
>
>ANTLR complains about two nondeterminisms. The first one is for
>NUMERICOID (and OID also) and NUMBER and the second one is for DESCR
>(and OIS also) and ID_AND, ID_OR...
>

For NUMBER, need to left factor the LDIGIT in both alternatives, try:

NUMBER : '0' | ( LDIGIT ( DIGIT )* ) ;

For DESCR, please read the Antlr documention about the tokens {...}
section in a lexer, the testLiterals=true option, and generally how to
deal with Keywords that look like Identifiers (don't remember the
specific chapter(s) in the docs, sorry).

Hope this helps...
   -jbb


More information about the antlr-interest mailing list