[antlr-interest] Keywords as identifiers : how to resolve a non-determinism ?

Петров Александр gmdidro at gmail.com
Fri Jun 6 14:29:35 PDT 2008


Could you create tokens' definition for ambitious indentifiers ? I
haven't have understood the moment clearly, but it seems, that such
code works:

Inspired by this post -
http://www.antlr.org/pipermail/antlr-interest/2003-May/003888.html

options
 {
  language = "CSharp";
 }

 class SimpleGrammar2Parser   extends  Parser;

 options {
   k = 2;
   defaultErrorHandler = false;
 }

 prog: (stat)+ ;

 stat:  IF   expr stat
      | CALL ID   SC
      | SC
      ;

 expr: ID
     ;

 class SimpleGrammar2Lexer extends Lexer;

 options {
  k = 2;
  testLiterals=false;
 }

//  TOKENS  !!
tokens
{
 IF="if";
 CALL="call";
}

 WS    : (  ' '
           | '\t'
           | ( options { generateAmbigWarnings = false; }
               : '\r' '\n'
               | '\r'
               | '\n'
             ) { newline(); }
          )  {$setType ( Token.SKIP ); }
       ;

 SC : ';';
 ID options { testLiterals = false; }  /// CHANGED from "true" to
testLiterals = false
  :
   ( 'a'..'z')('a'..'z')*
  ;

> Is it possible to walk around this problem specifically under ANTLR 2.7.5 ?
>
> Thanks.
>
> Yury
>


More information about the antlr-interest mailing list