[antlr-interest] If it's a date it's a date else it is not...

Des Hartman des at deshartman.com
Fri Mar 13 19:46:01 PDT 2009


I need some help defining a parser that parses a line of text to the EOF.
This is similar to the text entered in an Excel formula editor. The problem
I have is that I cannot get the grammar to properly identify a date as
below, else fail. The idea is that if it is NOT a date, the cell will be
treated as a string.

The problem I am having is that the parser does the matching plus a
mismatchedTokenException, which I presume is the extra "/" instead of a EOF.
Ideally I want the parse to check if the text is a date, else let it be
picked up by matching a string. Please help.

cell
     : number
     | date
     | string
     ;

date    : NUMBER ' ' MONTH ' ' NUMBER EOF
          | NUMBER '/' NUMBER EOF
          | NUMBER '/' NUMBER '/' NUMBER EOF
          | MONTH ' ' NUMBER EOF
          | NUMBER ' ' MONTH EOF
    ;

===================================

5/5/5 evaluates to Date correctly
5/5/5/5 evaluates to Date 5/5/5 and mismatchedToken

Thanks
Des
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090314/88766d2b/attachment.html 


More information about the antlr-interest mailing list