[antlr-interest] ANTLR for Python

Terence Parr parrt at cs.usfca.edu
Fri Nov 5 13:45:54 PST 2004


On Nov 5, 2004, at 1:56 AM, Marq Kole wrote:
> Hi,
>
> I've just uploaded the latest patch in the Files/ANTLR Python
> directory. It now runs all examples flawlessly and has the build
> process for the Python runtime integrated in the ANTLR build
> process.

Wow!  Amazing.  Great work :)

> I am looking for a few extensions in the way ANTLR handles Python
> grammars. At this moment the header { } block is supported, but just
> like the C++ runtime has the option to have different kinds of
> headers, whose contents are placed in different parts of the
> generated code, I would like to have something similar in Python. To
> be more precise, I would like to have a header whose contents are
> added to the __init__ method of the generated parser, and also a
> header whose contents are added at the end of all generated code, at
> the outer indentation level. That would allow one to add self-
> testing code to the grammar, or add another class that uses the
> creater scanner/parser/treeparser classes directly.
>
> Could someone give me a pointer to where in the ANTLR source code
> this kind of stuff is handled so I can add the
> abovementioned "headers"?

Well, I normally just add any action before the grammar rules to the 
output class, which can include

{
.... __init__ ...
}

Then you don't need to mess with the header thing.

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!





 
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