[antlr-interest] Sub-Lexers?

C. Mundi cmundi at gmail.com
Sun Aug 16 10:06:38 PDT 2009


I feel like I'm being denser than usual so any clue will do...

Suppose I have a legacy configuration file with an ad hoc grammar and
now I need to write a clean parser for it.  The parser is trivial if
the lexing is done cleanly.  The 'language' has easily detected and
disambiguated 'clauses' but each clause has its own dialect and some
dialects are in syntactic conflict.  For example a reserved word in
one dialect is legal freeform text in another and no (elegant)
predicate can handle all ambiguous contexts.

What I'm thinking is a lexer which finds the clauses followed by a
parser which does a trivial rewrite which embeds actions to invoke
specialized lexers for each clause type.  All of the specialized
levers target a single AST which is handled by a unified parser.

Seems like a lot of work to fake out 'sublexing'.  There must be a
better way to think about this.

Thanks for reading!
~Carlos


More information about the antlr-interest mailing list