[antlr-interest] MismatchedTokenException in simple grammar

Parker, Joel J. K. (GSFC-5950) joel.j.k.parker at nasa.gov
Tue Mar 9 11:53:19 PST 2010


Hi all,

I'm completely new to ANTLR and EBNF grammars to begin with, so this is probably a basic issue I'm simply not understanding.

I have a rule such as:

version_line : WS? 'VERS' WS? '=' WS? '1.0' WS? EOL ;
WS : ' '+ ;
EOL : '\r' | '\n' | '\r\n' | '\n\r' ;

that matches a statement in my input file that looks like this (with optional whitespace):
VERSION = 1.0

With the rule form above, I'm getting a successful match, although I get an exception with this form:

version_line : WS? 'VERS' WS? '=' WS? '1' '.0' WS? EOL ;

or this form:

version_line : WS? 'VERS' WS? '=' WS? DIGIT '.0' WS? EOL ;
DIGIT : '1' ;

Why is this different? I discovered this issue when trying to decompose the rule even more, hopefully ending up with something like this:

version_line : WS? 'VERS' WS? '=' WS? DIGIT '.' DIGIT WS? EOL ;
DIGIT : '0'..'9' ;

Thanks in advance,

-- 
Joel Parker


More information about the antlr-interest mailing list