[antlr-interest] C# example of "lexical filter mode" ??

Bart Kiers bkiers at gmail.com
Thu Feb 18 11:06:08 PST 2010


Hi John,


On Thu, Feb 18, 2010 at 7:52 PM, John Pool <j.pool at ision.nl> wrote:

> ...
>
> Question: how do I 'execute' such a grammar lexer in C# without feeding it
> into a parser?
>
>
You probably meant to instantiate a FuzzyLexer instead of a FuzzyParser
(unless your lexer grammar is called FuzzyParser, of course...).
Try this:

        ANTLRStringStream in = new ANTLRStringStream("...some source
as a String...");
        FuzzyLexer lexer = new FuzzyLexer(in);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        for(Object obj : tokens.getTokens()) {
            Token token = (Token)obj;
            System.out.println(token);
        }

Although the code above is Java, the C# variant can't be that much
different.

For a complete example how to use such a lexer, see the first answer from
this post on Stackoverflow:
http://stackoverflow.com/questions/2284571/how-to-match-a-comment-unless-its-in-a-quoted-string




>
> I tried downloading http://www.antlr.org/download/examples-v3.tar.gz, as
> suggested in the book, but that URL won't open.
>

No problem here: I can download that file just fine.

Regards,

Bart.


More information about the antlr-interest mailing list