[antlr-interest] Resolving ambiguities in Lexer rules

Achint Mehta achintmehta at gmail.com
Fri Aug 14 22:41:32 PDT 2009


Hi All,

The section "Ambiguities and Non determinisms" of the book "The definitive
ANTLR guide" talks about the ambiguities in lexer rules, but I am not sure
how to resolve them.

Consider a following grammar which assigns a value to an ID. The ID can
either be VERSION or COUNT while its value can be anything:
-----------------------------------------------
grammar sample_parser;

requestline : ver EQUAL SPECIAL_STRING ;

/* Tokens */
ver:('VERSION'| 'V') {}
      | ('COUNT' | 'C') {} ;


SPECIAL_STRING:(CHAR)+ ;
WHITESPACE: ' ';
NEWLINE: ('\r')? '\n';
EQUAL: '=';

fragment
CHAR: (('a'..'z')|('A'..'Z'));
-----------------------------------------------

If the input is given as
VERSION=FIRST
Then it works, but if following input is given
VERSION=VERSION
Then I get an error (MissingTokenException after the "=").

How can this ambiguity be resolved ?

Thanks in advance.

Regards,
Achint
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090815/83c3cc1b/attachment.html 


More information about the antlr-interest mailing list