ANTLR lexer mismatches tokens

Posted by Barry Brown on Stack Overflow See other posts from Stack Overflow or by Barry Brown
Published on 2010-04-09T06:18:24Z Indexed on 2010/04/09 6:23 UTC
Read the original article Hit count: 521

Filed under:
|
|
|
|

I have a simple ANTLR grammar, which I have stripped down to its bare essentials to demonstrate this problem I'm having. I am using ANTLRworks 1.3.1.

grammar sample;

assignment  :  IDENT ':=' NUM ';' ;

IDENT       :  ('a'..'z')+ ;

NUM         :  ('0'..'9')+ ;

WS          :  (' '|'\n'|'\t'|'\r')+ {$channel=HIDDEN;} ;

Obviously, this statement is accepted by the grammar:

x := 99;

But this one also is:

x := @!$()()%99***;

Output from the ANTLRworks Interpreter:

ANTLR Interpreter diagram

What am I doing wrong? Even other sample grammars that come with ANTLR (such as the CMinus grammar) exhibit this behavior.

© Stack Overflow or respective owner

Related posts about antlr

Related posts about lexer