title: Token with different interpretations (i.e. keyword and identifier)
body: <p>I am writing a grammar with a lot of case-insensitive keywords in ANTLR4. I collected some example files for the format, that I try to test parse and some use the same tokens which exist as keywords as identifiers in other places. For example there is a <code>CORE</code> keyword, which in other places is used as a <code>ID</code> for a structure from user input. Here some parts of my grammar:</p>
  
  <pre><code>fragment A : [aA]; // match either an 'a' or 'A'
  fragment B : [bB];
  fragment C : [cC];
  [...]
  CORE:        C O R E ;
  [...]
  IDSTRING:    [a-zA-Z_] [a-zA-Z0-9_]*;
  id:          IDSTRING ;
  </code></pre>
  
  <p>The error thrown then is <code>line 7982:8 mismatched input 'core' expecting IDSTRING</code>, as the user input is intended as <code>IDSTRING</code>, but always eaten by the keyword rule. In the input it exists both as keyword and as id like this:</p>
  
  <pre><code>MACRO oa12f01
      CLASS CORE ; #here it is a KEYWORD
  [...]
  SITE core ; #here it is a ID
  </code></pre>
  
  <p>Is there a way I can let users use some keywords as identifiers by changing my grammar somehow like "casting" the token to <code>IDSTRING</code> for conjunctive rules like this or is this a false hope in not hand written parsers?</p>