[antlr-interest] header sections (was: Re: ANTLR for Python)

Marq Kole marq.kole at philips.com
Wed Nov 17 01:22:54 PST 2004



--- In antlr-interest at yahoogroups.com, Ric Klaren <klaren at c...> 
wrote:
> On Mon, Nov 15, 2004 at 10:27:31PM -0000, Marq Kole wrote:
<SNIP>

Ric,

Thanks for the explanation, I got it working in one go.

Now that I have had a look at it, I am beginning to wonder: the 
header section seems to be generic, so not tied to either a lexer, 
parser or treeparser in particular. The ANTLR manual as it is did 
seem to acknowledge that impression. So if I have a file with both a 
lexer and a parser, a named header section will be added to both 
generated classes, that is: the same named header. If you do 
anything else than including headers in such a header section (for 
instance, defining auxillary classes or functions, or global 
variables) it will result in duplicated code.

So would we need to put a warning in the manual sections on Cpp and 
Python runtime (don't know if C# uses those) that if you use named 
headers you'd better make separate grammar files for your lexer, 
parser and treeparser.

Alternatively, we can do some clever processing on the named header 
files (this is just a proposal). If I want a named 
section "__init__" - I'm going to the scheme devised for Python now -
 to be used only for the lexer class, I could provide a 
name "<LexerClassName>.__init__" for the header. In the case there 
is also a parser in the file, that would not get the code in this 
header section. By using the actual name of the class instead of a 
name "lexer.__init__" it would even be possible to address this 
issue with 2 lexer definitions in the .g file (if that is at all 
possible). 

Marq






 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list