title: Spreadsheet FixedCell reference ($a$1, $a1, a$1 etc...) issue in ANTLR grammar
body: <p>I'm working on editing features for a web spreadsheet where I need to identify the cell references, range references and then coloring them as per my requirement. I'm able to identify and color the cell references but failed to identify the fixed cell references ($a$1, $a1, a$1 etc...) as it is throwing an error after entering dollar ('$') symbol.Can anyone help me on this.</p>
  
  <p>When I try to enter the cell reference as "$A$1", it is throwing no viable exception after entering second dollar symbol for row reference and i'm not sure why. How to read the "$" symbol to recognize the fixed cell reference?</p>
  
  <p>FYI, I've extended the grammar found @ <a href="https://stackoverflow.com/questions/5981206/antlr3-generating-a-parse-tree">antlr3 - Generating a Parse Tree</a></p>
  
  <p>I'm using the grammar for cell/range reference as below </p>
  
  <pre><code>CELLREFERENCE
      :  '$'?('a'..'z'|'A'..'Z')+'$'?('0'..'9')+
      ;
  
  RANGEREFERENCE
      : '$'?('a'..'z'|'A'..'Z')+'$'?('0'..'9')+ ':' '$'?('a'..'z'|'A'..'Z')+'$'?('0'..'9')+
      ;
  
  This will work for identifying the colon,
  
  RANGEREFERENCE : CELLREFERENCE ((':' CELLREFERENCE)=&gt; ':' CELLREFERENCE)?;
  
  Still not sure about the '$' issue in cell reference.
  </code></pre>
  
  <p>Please find the complete grammar here:</p>
  
  <pre><code>grammar Excel;
  
  options {
    output=AST;
    language=JavaScript;
  }
  
  tokens {
      // define pseudo-operations
      FUNC;
      CALL;
      NEGATE;
  }
  
  parse
    :  exp EOF -&gt; exp
    ;
  
  exp
    :  orExp
    ;
  
  orExp
    :  andExp (OR^ andExp)*
    ;
  
  andExp
    :  eqExp (AND^ eqExp)*
    ;
  
  eqExp
      : relExp (( EQUALS | NOTEQUALS)^ relExp)*
      ;
  
  relExp
      : addExp ( (LT^|LTEQ^|GT^|GTEQ^) addExp)*
      ;
  
  addExp
      : multExp ( (PLUS^| MINUS^) multExp)*
      ;
  multExp 
      : unaryExp (( MULT^ | DIV^ | MOD^ |POW^| IS^) unaryExp)*
      ;
  
  unaryExp
    :  NOT atom -&gt; ^(NOT atom)
    |  MINUS atom -&gt; ^(NEGATE atom)
    |  ASSIGN atom -&gt; ^(ASSIGN atom)
    |  atom
    ;
  
  atom
    :  TRUE
    |  FALSE
    |  INT
    |  FLOAT
    |  function
    |  CELLREFERENCE
    |  RANGEREFERENCE
    |  '(' exp ')' -&gt; exp
    ;
  
  POW : '^';
  DIV : '/';
  MOD : '%';
  MULT : '*';
  PLUS : '+';
  MINUS : '-';
  LT   : '&lt;';
  LTEQ : '&lt;=';
  GT   : '&gt;';
  GTEQ : '&gt;=';
  EQUALS : '==';
  ASSIGN: '=';
  NOTEQUALS : '&lt;&gt;';
  INT    : '0'..'9'+;
  FLOAT  : ('0'..'9')* '.' ('0'..'9')+;
  OR     : 'or' ;
  AND    : 'and' ;
  IS     : 'is' ;
  NOT    : 'not' ;
  TRUE   : 'true' ;
  FALSE  : 'false' ;
  
  function
      :   IDENT '(' ( exp (',' exp)* )? ')' -&gt; ^(FUNC IDENT (exp)*)
      ;
  CELLREFERENCE
      :  '$'?('a'..'z'|'A'..'Z')+'$'?('0'..'9')+
      ;
  
  RANGEREFERENCE
      : '$'?('a'..'z'|'A'..'Z')+'$'?('0'..'9')+ ':' '$'?('a'..'z'|'A'..'Z')+'$'?('0'..'9')+
      ;
  
  IDENT
      :   ('a'..'z' | 'A'..'Z') ('a'..'z' | 'A'..'Z' |'0'..'9')*
      ;   
  
  SPACE  : (' ' | '\t' | '\r' | '\n') {$channel=HIDDEN;} ;
  
  ERRCHAR : Err =. { /*console.log($Err);*/ } ;
  </code></pre>