what is the ordering of an AST tree?
Erwin S. Andreasen
erwin+usenet at andreasen.org
Sat Mar 6 03:13:36 CET 2004
"stephene at sjsoft.com" <stephene at sjsoft.com> writes:
>>In my experience ( not analysis ;)..yes--it's in the same order. Here's
>>the deriver module I ended up with last week, and some unittests which
>>demonstrate that, for simple expressions, at least, order is preserved.
> Great. I'm really hoping that that holds true for all cases. For now I'll
> just deal with the simple expressions.
> What I am trying to do then is essentially locate the most recent
> assignment that a variable has been given. The way I would assume to do
> that would be to traverse up the tree (assuming it is in fact in the order
> of the program flow) and search for the closest ASSIGN node that involves
> the variable name specified.
You may also have to go "sideways". E.g.:
if x > 42:
val = True
val = False
Currently I'm working on some code to do small-scale static type
checking in Python using symbolic interpretation, which is essentially
a process where you do pseudo-evaluation of the code, noting variables
and their types and any problems.
Maybe such a process could also be useful to you, since at the same
time you can also note where each variable is assigned. It's fairly
easy with the help of compiler.visitor.
<erwin+usenet at andreasen.org> Herlev, Denmark
More information about the Python-list