[antlr-interest] Question

Mikael Sandberg mikael.sandberg at addiva.se
Wed Oct 31 01:41:11 PDT 2007


Hi!

I am writing a parser and evaluator for a small expression language,  
it is not even Turing complete but still gives me problems, the  
language was created by person(s) not well adversed in the fine art of  
programming language construction, that is for sure.

The language is basically stripped from all spaces before passed to  
the parser. It becomes difficult to parse and differetiate between for  
instance an ID and a literal folowed by a int, like in this short  
example:

grammar Test;

start	:	'literal' INT
	;
	
INT	:	'0'..'9'+
	;
	
ID	:	'a'..'z' ('a'..'z' | '0'..'9')*
	;

The input "bit 1" works fine but without the space "bit1" the parser  
or rather the lexer creates a token for "bit1" that is not part of the  
language. Is there a fast fix for this problem? You write in the book  
that this was a common situation and that ANTLR takes care of it but  
it seems that in this case it is not so.

Thank you for your time.

Yours
Mikael Sandberg


More information about the antlr-interest mailing list