[antlr-interest] Import--can someone explain how to make it work

Todd O'Bryan toddobryan at gmail.com
Sun Nov 16 11:08:38 PST 2008


Piggybacking on a recent post about import issues, I'm having trouble
understanding how everything fits together.

>From the Wiki, I've figured out that lexer grammars can only import
lexer grammars, parser grammars can only import parser grammars, and
combined grammars can only import lexer or parser grammars, but not
combined grammars.

If I read this correctly, you can only have a single combined grammar
in any grammar you write that imports other grammars and it has to be
*the* grammar that imports all the other grammars. Is that correct?

Is it also the case that a tokens section is only allowed in a
combined grammar? I know it's not allowed in a lexer grammar, but it
doesn't seem like it would make sense at all in a parser grammar, so
then there can only be one tokens section in any grammar that consists
of more than a single file. Again, is that correct?

Given these constraints, can somebody provide a decent heuristic for
how to break up grammars? I've got a bunch of pieces that need to fit
together, but given the constraints on putting them together, I'm not
sure where to start. I have some rules that combine parsing with
lexing and these can only go in the grammar that imports everything
else, but they don't logically belong there.

Am I missing something basic here, or is the grammar inheritance
system a work in progress that's still a bit too picky to be as useful
as it could be?

Todd


More information about the antlr-interest mailing list