[antlr-interest] Multiple lexers with one parser

Susan Jolly easjolly at ix.netcom.com
Sat Jun 30 13:25:04 PDT 2007


I've just gotten my copy of the new ANTLR v3 book and am happy and amazed to
discover how much I will be able to simplify my current ANTLR v2
application.  

However I have a question about the best approach to using multiple lexers
with a single parser in v3.  (I know I could use lexer states in a single
lexer but I've found that my current use of multiple lexers considerably
simplifies maintenance for this lexer grammar.)

It appears that in v3 all that is required for multiple lexer instances to
share the same input is for them to each be created using the same instance
of the input stream. So my question is how to handle the multiplexing?

It looks as though subclassing nextToken() in the primary lexer so as to
obtain tokens from auxiliary lexers is one strategy.  Is this the best
approach?

Thanks! 




More information about the antlr-interest mailing list