[antlr-interest] [Lexer] how to make keyword case insensitive?

sishen sishen_freecity at 126.com
Wed Sep 20 23:44:35 PDT 2006


Hey. everyone.

How can i make keywork case insensitive?

in my Lexer options, i have already turn off the caseSensitive.

options {
  testLiterals=false;    // don't automatically test for literals
  k=3;                         // two characters of lookahead
  caseSensitive=false;
}

But i found that it does't make sence to 'tokens';

tokens {
    AND = "and";
}

I want [A|a][N|n][D|d] match the keyword AND.  But only "and" matches.

I can define as this way:

AND : "and";

it works. But have a conflict with IDENT.
IDENT
  options {testLiterals=true;}
  : ('a'..'z') ('a'..'z'|'0'..'9')*
  ;

Of course it does.

I hate the warning. So i not prefer this way.

query.g: warning:lexical nondeterminism between rules AND and IDENT upon
query.g:     k==1:'a'
query.g:     k==2:'n'
query.g:     k==3:'d'


I want to know whether there is another way which an make keyword case 
insensitive? 
What should i do?



More information about the antlr-interest mailing list