[antlr-interest] Unexpected char when generating lexer

Thiago Arrais thiago.arrais at gmail.com
Tue Dec 20 12:28:25 PST 2005


2005/12/20, Gregg Reynolds <dev at arabink.com>:
> Try using single quotes:  '\u0000'.  That works for me.

Weird. The following grammar (with single quotes) gives me the same error.

---- start grammar ---
class TestLexer extends Lexer;

ASCII : "NUL" { $setText('\u0000'); } ;
---- end grammar ---

I have antlr 2.7.5 here. What version are you using?

This is pretty weird, the docs for my version say that the semantic
action blocks are simple character sequences. Although, in these
special case, they aren't (i.e. the '$' isn't pure Java and needs to
be translated into Java code by antlr).

When fed with this other slightly different grammar, antlr is able to
generate code. This one doesn't have the '$' special character.

---- start grammar ---
class TestLexer extends Lexer;

ASCII : "NUL" { setText("\u0000") ;} ;
---- end grammar ---

This approach worked for me, but I wonder if there is any hidden issue now.

Any ideas?

Thanks,

Thiago Arrais


More information about the antlr-interest mailing list