[antlr-interest] ANTLR does not properly recognise single characters?

Gavin Lambert antlr at mirality.co.nz
Sun Dec 30 19:32:57 PST 2007


At 13:04 31/12/2007, Mark wrote:
 >I'm having some rather strange behaviour from ANTLR when 
presenting
 >it with single character tokens.  I have the following declared:
 >
 >L	:	(('A'..'Z')|('a'..'z')|'_');
 >N	:	('0'..'9');
 >IDENTIFIER  :	L ((L|N)*);
 >
 >But when I run my parser I've seen the following error:
 >> line 3:10 mismatched input 't' expecting IDENTIFIER

"t" could match either L or IDENTIFIER, since they're both public 
(non-fragment) tokens.  L will win, since it's listed first.

"tu" could match either two Ls or one IDENTIFIER.  In this case, 
IDENTIFIER will win, since it's fewer tokens.

You probably want to make both L and N fragment rules.



More information about the antlr-interest mailing list