[antlr-interest] keywords

John B. Brodie jbb at acm.org
Thu Aug 3 06:52:11 PDT 2006


Abhijit Nandkumar Ghonge asked:
>Hi,
>
>            I'm a newbie in Antlr. I have a grammer that uses keywords
>like if , while and so on . But all of these are case insensitive. If I
>directly use these in my parser as literals, can they be case
>insensitive.
>
>            Right now I have defined the keywords in the lexer with
>options caseSensitive set to false. E.g
>...snipped...

Hi!

For Antlr v2 you should define your keywords in a tokens section
rather than defining them in individual rules. Something like:

tokens {
   ENDIF = "endif";
   THEN = "then";
// ... and the rest of the keywords go here ...
}

Also you want the `options { testLiterals = true; }` phrase on just
the LITERAL rule and not on its protected sub-rules.

Hope this helps...
   -jbb


More information about the antlr-interest mailing list