mwh at python.net
Tue Aug 17 18:50:36 CEST 2004
Christopher T King <squirrel at WPI.EDU> writes:
> On Mon, 16 Aug 2004, Michael Hudson wrote:
> > Christopher T King <squirrel at WPI.EDU> writes:
> > > (Unfortunately, AST trees don't match up exactly with Python grammar, so
> > > I'm having to learn the format by trial-and-error. Not much fun. Is
> > > there documentation on the AST forms anywhere?)
> > Which AST are you talking about?
> Whatever is spit out by parser.suite().
Ah. This isn't, in any sense, an ABSTRACT syntax tree, despite what
bits and pieces of the documentation say, or at least used to say.
You'll almost certainly have a better time using the output of
> Things like grammar.txt's "statement" being represented symbol.stmt,
> and grammar.txt's stmt_list not existing at all in the AST trees
> (though most/all of the other _lists exist).
As Terry said, grammar.txt is documentation only...
> > Which version of Python, etc?
> 2.3. I'm using http://docs.python.org/ref/grammar.txt as my grammar
Grammar/Grammar in the source is much more accurate, but really, you
want to use compiler.transformer.
compiler.transformer spits out classes defined in compiler.ast, which
*claims* to be autogenerated from Tools/compiler/ast.txt, but I'm not
sure if that's actually the case any more.
Even without documentation, they are easier to work out than the raw
output of the parser module.
"Also, does the simple algorithm you used in Cyclops have a name?"
"Not officially, but it answers to "hey, dumb-ass!"
-- Neil Schemenauer and Tim Peters, 23 Feb 2001
More information about the Python-list