Python Virtual Machine Reference

Jeff Epler jepler at unpythonic.net
Thu Feb 19 02:41:03 CET 2004


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.

The numeric values for nodes in the AST are subject to change between
releases.  The numbers for the AST nodes for tokens are chosen manually,
and the numbers for productions (stmt, expr_stmt, atom, etc) are a
consequence of the order of appearance in the Grammar file.

Like the bytecode, the AST is really an implementation detail of
cpython.

Jeff




More information about the Python-list mailing list