1

identification for ID :

ID  :   ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
    ;

when I parse my rules it , only char 'a' cannot be recognised ,but 'A' or 'aa' or 'a0' or 'b' or 'c' or 'AAAZzzzxx' or .... everything else in universe except 'a' can be recognized by lexer why not 'a'??

error :

mismatched input 'a' expecting 'u0005'

thanks!

Yank
  • 718
  • 6
  • 17
  • 2
    Does your parser grammar reference `'a'` explicitly anywhere? If so, ANTLR is quietly producing a new lexer rule that matches `'a'` before `ID` gets a chance to see it. If you can add that part of your grammar to the question (assuming it exists, which is just a guess), someone may be able to help you work around the problem. – user1201210 Dec 12 '12 at 01:15
  • A:'a'; I found this basters ... thanks , it's simple but tricky :) – Yank Dec 12 '12 at 01:21

1 Answers1

-1

Your rule can match ZERO characters and so the lexer will go haywire. You need:

ID  :   ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')+
;

See the '+' instead of '*'?

Jim

Jim Idle
  • 317
  • 1
  • 3
  • 3
    The `ID` rule in the question matches one or more characters. The rule in this answer matches two or more characters. – user1201210 Dec 12 '12 at 05:54