How does python build its AST

MonkeeSage MonkeeSage at gmail.com
Sat Dec 8 01:50:43 EST 2007


On Dec 8, 12:20 am, "Terry Reedy" <tjre... at udel.edu> wrote:
> "MonkeeSage" <MonkeeS... at gmail.com> wrote in message
>
> news:7e222fec-8b84-49d7-a9bc-113520d7ed91 at t47g2000hsc.googlegroups.com...
> | 1.) What is the benefit of doing a two phase compilation (parsing/
> | compiling), rather than a single, joint parse + compile phase (as in
> | interactive mode)?
>
> As far as I know (without looking at the code), there is no difference
> between interactive and batch mode except that the unit processed is a
> statement versus file.

I see.

> | 2.) Wouldn't it be possible on the parsing phase to "tag" names as
> | valid, even if they occur prior to the assignment of the name, if on a
> | later branch that assignment is found (and have the compiler be aware
> | of such tags)?
>
> What would be the point?  The semantics of Python code is essentially
> independent of whether it is executed in interactive or batch mode.  (The
> exceptions are not relevant to your question.)  So there is no point I can
> see to doing something in file mode that could not be done in statement
> mode.

It would pretty much be pointless. Referencing a name before it's
assigned seems confusing and strange to me. I suppose one sane use
would be in implementing something like Haskell's "where" clause, but
I don't think that would work well (or even be very useful) in python.
Anyhow, this was more of an academic curiosity on how CPython does
things, and I appreciate your answers.

> tjr

Regards,
Jordan



More information about the Python-list mailing list