[antlr-interest] Parsing question
Ivan Brezina
ibre5041 at ibrezina.net
Thu Aug 2 02:59:01 PDT 2012
Quoting Vinay Pandit <vpandit at quantivo.com>:
> I am trying to parse a date time literal in ANTLR and I am having
> issues with the grammar.
>
> Here are the rules defined in the parser
>
> dateValue : ( yearValue MINUS monthValue MINUS dayValue);
>
> yearValue : datetimeValue ;
>
> monthValue : datetimeValue;
>
> dayValue : datetimeValue;
>
> datetimeValue : UNSIGNED_INTEGER;
>
> The Lexer has
>
> MINUS : '-' ;
> DIGIT : ('0'..'9');
> UNSIGNED_INTEGER : (DIGIT) +;
>
>
Your rule dateValue is a parser one.
I means that it could accept input containing whitespaces and comments like:
2010 - /* blblbala*/ 01 - 01
Such an input is obviously ambiguous = it is also a numerical
expression (the result is 2008).
You probably want dateValue to be a Lexer rule (the one starting with
capital letter).
Also beware that the order of Lexer rules is important.
Ivan
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
More information about the antlr-interest
mailing list