[antlr-interest] Lexer and Parser class packaging

Brian DeVries contingencyplan at gmail.com
Mon Feb 5 18:56:18 PST 2007


On 2/5/07, Gavin Lambert <antlr at mirality.co.nz> wrote:
>
> 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 :)


Ditto. :-)

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.


This is what I'm arguing for.

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.


For what it's worth, I'd advocate getting rid of @header entirely. If we
have the individual versions and the combined syntax (which exists as a
convenience), then we have no need for the unqualified @header anymore. It
only serves as a point of ambiguity, and necessitates a "special case".

Furthermore, if this change were implemented, we have a lot of ANTLR v3
grammars (mine included) that expect @header to send its contents to the
parser only. If we change the semantics of the @header section to have it
send its contents to both the parser and lexer, then grammar writers may
encounter unexpected behavior when they upgrade. Removing @header entirely
will cause the ANTLR system to emit a syntax error (hopefully with some
helpful output), and the grammar writers can update their grammar easily.
The change from @header to @parser::header is minimal (9 characters),
requires no changes to the contents of the header, and has no additional
side effects.

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.
>

Similarly for these - if we change their semantics, but leave them intact
syntactically, then we'll get a lot of upset ANTLR users posting in here
about the change. If we change the syntax, and point them in the right
direction when they run it through, then they'll grumble about it, but
probably just to themselves instead of the mailing list. ;-)

@ Mr. Idle: I'm coming up with a retort, though I'll email you individually
so as not to derail the discussion (moreso than I have). :-)

Thanks,
~Brian DeVries
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070205/73b6732d/attachment.html 


More information about the antlr-interest mailing list