[antlr-interest] How to make case insensitive token checker for the lexical analysis part of antlr in C program?

Jim Idle jimi at temporal-wave.com
Wed Oct 5 09:04:46 PDT 2011


See the wiki FAQ article. However, the built in conversion is only ASCII
friendly, so you would have to write your own UTF8 version. Then you install
the pointer to your function in place of the default one (look at the source
code for setUcaseLA()) in your input stream.

http://www.antlr.org/wiki/pages/viewpage.action?pageId=1782



Jim



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of ??
> Sent: Wednesday, October 05, 2011 5:30 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] How to make case insensitive token checker
> for the lexical analysis part of antlr in C program?
>
> Hi,all
>
> I want to convert the token stream into upper case at the time when
> lexical rules are checked.
>
> In java, we can do it in this way:
> <pre>
> public class ANTLRNoCaseStringStream extends ANTLRStringStream {
>     public ANTLRNoCaseStringStream(String input) {
>         super(input);
>     }
>
>     @Override
>     public int LA(int i) {
>         int returnChar = super.LA(i);
>         if (returnChar == CharStream.EOF) {
>             return returnChar;
>         } else if (returnChar == 0) {
>             return returnChar;
>         }
>         return Character.toUpperCase((char) returnChar);
>     }
> }
> </pre>
>
> then,
> <pre>
> // assume that we are going to make a SQL parser.
> SQLLexer lexer = new SQLLexer(new ANTLRNoCaseStringStream(command))
> </pre>
>
> But, my question is that: how to do the same thing in C program?
> I looked into antlr3 C runtime source, but could not find a way to
> archive this.
> In fact, I'm a java programmer, new to C, the source code really
> confused me  >_<
>
> By the way, could you figure out any open sourced C project that using
> antlr3?
>
> Thank you in advance.
>
> --
> 金杰
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list