[antlr-interest] How do you structure a two-part lexer?

Steve Cooper steve at stevecooper.org
Sat May 30 00:41:56 PDT 2009


Thanks, Gavin!

Your comments have got me on the right track, I think. Also, the
Island grammar in the examples is the sort of thing I was hoping for.
I'd scanned the example input for it but hadn't noticed the dual
nature. I'd just seen a C-like language with some comments. I should
have looked a little closer.

So it seems that it's safe to have lexers share character streams; The
'master' island grammar does this;

JAVADOC : '/**' {
            ...
            JavadocLexer j = new JavadocLexer(input);

where that last line is hijacking the input stream.

I think I'll be going for one master lexer, one sub-lexer, a master
parser, and a sub-parser, like the island example. The two parsers can
share common state, like a common symbol table, to communicate.

Thanks again.

    Steve


More information about the antlr-interest mailing list