[antlr-interest] Parsing question

Jim Idle jimi at temporal-wave.com
Wed Aug 1 22:48:25 PDT 2012


That should be:

fragment
DIGIT ....

And you don't need separate parser rules for yearValue and the other two -
they are the same thing, just use UNSIGNED_INTEGER directly.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Vinay Pandit
> Sent: Wednesday, August 01, 2012 9:44 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Parsing question
>
> 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) +;
>
>
> When I parse a date like 2012-01-01 for the dateValue rule, the parser
> throws an exception.
>
> com. qexpr.ParseException: line 1:4 - mismatched input '-01' expecting
> MINUS
>                at
> com.quantivo.qexpr.AbstractQParser.reportError(AbstractQParser.java:77)
>                at
> com.quantivo.qexpr.SQLGrammar.dateValue(SQLGrammar.java:4730)
>                at
> com.quantivo.qexpr.model.SQLGrammarTest.testDateValue(SQLGrammarTest.ja
> va:25)
> ...
>
> Looking at the error message it is obvious that I am not getting the
> Minus token. Instead the internal token that I get is an INTEGER
> (signed). I tried the greedy=false option, but that did not seem to
> help either. I am running out of ideas as to why the input does not
> match. Obviously I am doing something wrong, but I am not sure what!
>
> Regards
> Vinay
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list