title: EBNF grammar (ANTLR)
body: <p>I've got a problem with EBNF grammar in ANTLRWorks:</p>
  
  <pre><code>line 37:    
  upper_lower_case
  : LOWER_CASE 
  | UPPER_CASE
  ;
  
  line 42:
  CLASSNAME 
  :   UPPER_CASE (DIGITS | upper_lower_case )*
  ;
  
  line 51:
  UPPER_CASE 
  :   'A'..'Z'
  ;
  
  line 55:
  LOWER_CASE 
  :   'a'..'z'
  ;
  
  line 60:
  DIGITS  :   '0'..'9'
  ;
  </code></pre>
  
  <p>I want CLASSNAME to always start with the capital letter and than it can consists of digits, upper or lower case letters.</p>
  
  <p>Error log:</p>
  
  <pre><code>[13:11:59] warning(200): classgenerator.g:43:42: 
  Decision can match input such as "'0'..'9'" using multiple alternatives: 1, 2
  
  As a result, alternative(s) 2 were disabled for that input
  [13:11:59] warning(200): classgenerator.g:43:42: 
  Decision can match input such as "&lt;EOT&gt;" using multiple alternatives: 2, 3
  
  As a result, alternative(s) 3 were disabled for that input
  [13:11:59] error(201): classgenerator.g:43:42: The following alternatives can never be 
  matched: 3
  
  [13:11:59] error(208): classgenerator.g:60:1: The following token definitions can never 
  be matched because prior tokens match the same input: UPPER_CASE,DIGITS
  </code></pre>
  
  <p>Could anyone help me solve this problem?
  Thanks in advance.</p>
  
  <p>Regards,
  Hladeo</p>
  
  <p>EDIT:</p>
  
  <p>So I should use fragment keyword if it doesn't refers to the tokens? In this way using fragment keyword will be wrong?</p>
  
  <pre><code>tokens {
  PUBLIC    = '+';
  PRIVATE   = '-';
  PROTECTED = '=';
  }
  
  fragment ACCESSOR
  : PUBLIC
  | PRIVATE
  | PROTECTED
  ;
  </code></pre>
  
  <p>and another question.</p>
  
  <pre><code>OBJECTNAME  
  :   UPPER_LOWER_CASE (UPPER_LOWER_CASE | DIGIT)*
  ;
  </code></pre>
  
  <p>OBJECTNAME should consists of at least one letter (upper or lower cased doesn't matter) and optionally of another letters or digits - what's wrong with that part of the code? When I try to type for example <code>variable</code> - it's okay, but when I start with capital letter <code>Variable</code> I'm getting an error:</p>
  
  <pre><code>line 1:15 mismatched input 'Variable' expecting OBJECTNAME
  </code></pre>