[antlr-interest] distinguishing between DIV and regular expression

Rodrigo B. de Oliveira rodrigobamboo at gmail.com
Wed Apr 5 04:06:25 PDT 2006


On 05 Apr 2006 12:42:42 +0300, Anakreon Mendis <anakreonmejdi at yahoo.gr> wrote:
> I have a little problem with a lexer and I hope you could help.
>
> The problem is the two tokens start with the same simbol.
> I have
> DIV : '/';
> and regex:
> REG_EXP :
> '/' COMMON_REG   (COMMON_REG | INNER_REG)* '/' ('g' | 'm' | 'i')*
> ;
>

I use predicates for boo:

DIVISION:
	("/*")=> ML_COMMENT { $setType(Token.SKIP); } |
	(RE_LITERAL)=> RE_LITERAL { $setType(RE_LITERAL); } |	
	'/' (
		('/' (~('\r'|'\n'))* { $setType(Token.SKIP); }) |			
			('=' { $setType(ASSIGN); }) |
		)
	;

The '/' can start any of multiline comment, regex literal and single
line comment.
--
bamboo
http://blogs.codehaus.org/people/bamboo/
Got objects? http://www.db4o.com/


More information about the antlr-interest mailing list