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

金杰 hellojinjie at gmail.com
Wed Oct 5 05:29:46 PDT 2011


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.

-- 
金杰


More information about the antlr-interest mailing list