title: Neat way to distinguish identifiers and variable names (ANTLR)?
body: <p>How can we distinguish a variable name, and an identifer, in an ANTLR grammar? </p>
  
  <pre><code>VAR: ('A'..'Z')+ DIGIT*  ;
  IDENT  :   ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'-')*;
  </code></pre>
  
  <p>The piece of grammar (in ANTLR) does not work because  the compiler will complain that IDENT may never be reached for some input. This seems to be a classic head-hack for compiler writers, <a href="http://en.wikipedia.org/wiki/The_lexer_hack" rel="nofollow">The lexer hack</a></p>
  
  <p>For the ANTLR users, Could you tell me your  neat way to work around it? Thanks</p>