[antlr-interest] unexpected char error

Gavin Lambert antlr at mirality.co.nz
Sat Mar 17 21:51:50 PDT 2007


At 15:26 18/03/2007, Kevin J. Cummings wrote:
 >1) Why does this work (code snippets only):
 >
 >EQ : '=' ;
 >UINT : ( '0'..'9' )+ ;
 >
 >stmt : "a" EQ UINT ;
 >
 >while this gives me errors when I run it:
 >
 >UINT : ( '0'..'9' )+ ;
 >
 >stmt : "a" "=" UINT ;
[...]
 >> Parse exception: <arguments>:1:8: unexpected char: '='

I believe it's because you haven't defined '=' anywhere in your 
lexer any more.  The lexer will normally only accept characters 
that it knows about, and since you haven't mentioned it anywhere 
it doesn't know what token to generate for it.

To solve this you can either define a token for it, as you did in 
your first example, or use a catchall token in combination with 
the charVocabulary lexer option.



More information about the antlr-interest mailing list