[antlr-interest] Lexer and Parser class packaging

Terence Parr parrt at cs.usfca.edu
Mon Feb 5 12:42:28 PST 2007


On Feb 5, 2007, at 8:40 AM, Martin Probst wrote:

> Hi,
>
>> You need to use @header::lexer and @header::parser. Otherwise the  
>> header element will only appear in one of them (can’t remember  
>> which it is now by default ;-).
>
> Why is that actually so? Apparently 95% of all beginners with ANTLR  
> 3 run into this problem, maybe you should simply adjust to the  
> users and make @header {} be inherited by both parser and lexer?

Well,  this has come up a number of times.  I suppose that

@header {package foo;}

Could split across both lexer and parser, but then @members {int i;}  
should parallel this and send the member declaration to both parser  
and lexer, which I can't agree with.

I don't like special cases; either we insist that the lack of a scope  
means both or it means parser.  Having one with some both and one  
assume parser is not correct.

You can see my conundrum here. clearly if we don't change this it  
will have to be the first entry in the FAQ ;)

Ter


More information about the antlr-interest mailing list