[antlr-interest] Mismatched Character, expecting set null

John B. Brodie jbb at acm.org
Sat Aug 7 04:39:28 PDT 2010


On Sat, 2010-08-07 at 04:31 -0400, Ken Klose wrote:
> I have arrived at a new problem that I can't resolve.  I am parsing a rather
> simple data file and have to read a field that can be a number of the forms
> "55", "+55", "-55", or ".." in case where no number has been assigned.  I've
> tried the following token definitions but get MismatchedTokenException on
> "55" and "+55".
> 
> These are two of the token definitions I have tried:
> 
> CHANGE: ( ( ('+' | '-')? DIGIT+) | '..' );
> CHANGE: ( ( ('+')? ('-')? DIGIT+) | '..' );
> fragment DIGIT: '0'..'9';

the first version looks like it should work.

the second is, of course, not proper as it would accept +-55 as a CHANGE
token, and that isn't one of your choices.

do you have any other lexer rules that recognize tokens that might begin
with a '+' or a DIGIT? 

you might try writing a small Java Lexer test rig that prints the
details of each token recognized.

try to boil your grammar down to the smallest, yet complete, example
grammar containing your problem. post that small example. and then maybe
we can help to further identify the issue.

sorry to have not been very helpful....
   -jbb




More information about the antlr-interest mailing list