[antlr-interest] warning:lexical nondeterminism between rulesVARTYPE and IDENT upon....

Nigel Sheridan-Smith nbsherid at secsme.org.au
Sun Jan 16 15:22:26 PST 2005


You might be better off making "int", "float", etc into proper literals. You
want a section:

class MyParser extends Parser;
tokens
{
  INT="int";
  FLOAT="float";
  ...
}

types: IDENT | basicTypes;

basicTypes: INT | FLOAT | ... ;


They will be matched at first as an IDENT, and then turned into INT, FLOAT,
etc when the literal test is performed.

Alternatively, you can skip the "tokens" section and just put the text
straight into your parser rules like this:

basicTypes: "int" | "float" | ... ;


If you *really* want your literals in the lexer (non-recommended), then
increase "k" so that the look-ahead can distinguish between one token and
another (in this example, at least 6 tokens are required to distinguish
between the alternatives):

class MyLexer extends Lexer;
options {
  k = 6;
}

HELLO: "hello";
HELLOTHERE: "hellothere";


However, I think this really slows down the speed of the lexer (and ANTLR's
generation phase) quite a bit... 

Nigel


> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of clocKwize
> Sent: Monday, 17 January 2005 9:39 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] warning:lexical nondeterminism between
> rulesVARTYPE and IDENT upon....
> 
> hey, in my lexer i have this:
> 
> VARTYPE
>     options { paraphrase = "a variable type"; }
>         :    ("int" | "float" | "string" | "bool")
>         ;
> 
> IDENT
>     options { paraphrase = "an identifier"; testLiterals = true; }
>         :    ('a'..'z' |'A'..'Z') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
>         ;
> 
> MyLexer.g: warning:lexical nondeterminism between rules VARTYPE and
> IDENT upon
> MyLexer.g:     k==1:'b','f','i','s'
> MyLexer.g:     k==2:'l','n','o','t'
> 
> it works ok as far as i know though, i'm not sure how to print a list of
> the tokens from the lexer into the console (cpp)
> 
> anyway, how do i turn the warning off?



--
Nigel Sheridan-Smith
PhD research student

Faculty of Engineering
University of Technology, Sydney
Phone: 02 9514 7946
Fax: 02 9514 2435



More information about the antlr-interest mailing list