[antlr-interest] Parsing question

Vinay Pandit vpandit at quantivo.com
Wed Aug 1 21:43:46 PDT 2012


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.java: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



More information about the antlr-interest mailing list