Python Virtual Machine Reference

Michael Hudson mwh at python.net
Thu Feb 19 06:29:30 EST 2004


Jeff Epler <jepler at unpythonic.net> writes:

> On Wed, Feb 18, 2004 at 10:20:37PM +0000, Dave Kuhlman wrote:
> > But, I don't understand what the connection is between the AST
> > (abstract syntax tree) and the byte code interpreter's op-codes.
> > Maybe someone else can explain that.  Perhaps the real Python
> > compiler does not use the AST.
> 
> The parser transforms the string of tokens into an AST, and then
> generates bytecode by traversing the AST.  After bytecode generation,
> the AST is discarded.

Which AST are we talking about here?

Python's built in parser produces an exceedingly concrete syntax tree
(ECST? :-).  This is the input to the builtin compiler
(Python/compile.c).  The Lib/compiler package translates the ECST into
a more genuine AST, and then walks over *that* to generate bytecode.

(The docs for the builtin parser module occasionally refer to the ECST
as an AST, but that's basically a lie).

What happens on the ast-branch (the "new compiler" branch), I'm not so
sure about.  An AST (AFAIK different from Lib/compiler's) is involved
somewhere, but I'm not sure how it's produced.

Cheers,
mwh

-- 
  Finding a needle in a haystack is a lot easier if you burn down
  the haystack and scan the ashes with a metal detector.
      -- the Silicon Valley Tarot (another one nicked from David Rush)



More information about the Python-list mailing list