[antlr-interest] Antlr 2.7 Header Sections

Ric Klaren ric.klaren at gmail.com
Tue Feb 6 10:28:26 PST 2007


Hi David,

On 2/6/07, Wigg, J D <wiggjd at lsbu.ac.uk> wrote:
> Please could someone confirm that it is not possible to set separate header
> sections in CPPParser and CPPLexer in Antlr 2.7 (or, if it is possible,
> please let me know how, or where I can find out)?
>
> The Antlr documentation doesn't say much about headers. It refers to
> "respective addendums". Please could someone let me know where they are?

For C++ it would be this one:

http://www.antlr.org/doc/cpp-runtime.html

If you got lexer and parser in the same file then they'll share the
same header sections. But attributes/methods added to the generated
classes are of course in the respective lexer/parser header files
(maybe a static attribute is an option, depends on what you want to
achieve)

> Basically what I want to do is to make information obtained by the lexer
> from Line Directives in the preprocessed *.i file available to the parser
> without involving an external file (thanks for your suggestion Xue Yong Zhi
> (Digest vol 27 no 2, 2 Feb) but I was already declaring them in another file
> (main.cpp)).

You might be able to pilfer the Token class implementation from this
version of your grammar:

http://pts14043.pts.nl/antlr/cppparser.tar.bz2

That way the real line/file information would be present on the token.

Cheers,

Ric


More information about the antlr-interest mailing list