[Python-Dev] Catching "return" and "return expr" at compile time

Greg Stein gstein@lyra.org
Wed, 08 Sep 1999 12:20:32 -0700

Fred L. Drake, Jr. wrote:
> Skip Montanaro writes:
>  > thing?  Ideally, I'd like to see a framework that brings the parser module's
>  > output up to a level where mere mortals like me can reason about Python
>   This was exactly what I wanted to prevent when I created the parser
> module!  ;-)
>   I think a wrapper that simplifies the parse tree wouldn't be too
> hard to do; you simply have to be sure that the simplified version can
> be re-elaborated to pass back to the byte-code compiler via
> parser.sequence2ast(<seq>).compile().  Otherwise you can't modify the
> tree without loosing line number information, which would be nice to
> keep around!

This has already been done. Grab the Python2C distribution from
http://www.mudlib.org/~rassilon/p2c/. There is a module named
"transformer.py" which does just what you're thinking -- it converts
Python's deeply-nested trees into something human-readable. Each of the
resulting node types are doc'd at the top of the module.

It is also over a couple years old, so it has had some decent


Greg Stein, http://www.lyra.org/