[antlr-interest] Lexer and Parser class packaging
Gavin Lambert
antlr at mirality.co.nz
Mon Feb 5 18:25:35 PST 2007
At 10:49 6/02/2007, Terence Parr wrote:
>
>So @members {int i;} should also code to both parser and lexer.
>Which makes you feel more uncomfortable? the inconsistency or
the
>fact that @header doesn't go to both? ;)
Inconsistency is simply inexcusable, so I guess that makes me the
most uncomfortable :)
But I was also proposing a third option: making unqualified
@header sections illegal. That's what I actually prefer over
sending it to both, if I had to choose one.
In my ideal world, you'd have the following constructs:
@lexer::header {} => written to lexer only
@parser::header {} => written to parser only
@lexer,parser::header {} => written to both
@header {} => special case
... where the unqualified version is accepted if only one of the
two are being generated (eg. only parser rules are supplied, or
it's specified as a 'lexer graamar' or 'parser grammar'), and
generates an error otherwise. Or maybe just generates a warning
and then writes it to both. I don't think it should quietly write
it to both and I definitely don't think it should write it to only
one if multiple files are being generated.
The same holds true for @members, and @footer (if such a thing
exists, and if not, it should, so that you can do namespaces in
C++, among other things). They all need to be consistent.
More information about the antlr-interest
mailing list