How is Python designed?

Diez B. Roggisch deetsNOSPAM at web.de
Mon Dec 6 11:05:04 EST 2004


Hi,

> 
> Not really. You think in this way, maybe because you
> know more about AST and less about that technique I
> mentioned. I thinked in the opposite
> way because I know different things better.
> Hehe.

So I guess you don't use classic parser techniques then?

> Sorry maybe I didn't understand that part correctly
> and took grant that it would be implemented in
> recursive way. I just wondered if the following can be
> extended for arbitrary length arithmetic expressions:
> Assignment("foo", BinaryOp("+", Get("a"),
> BinaryOp("*", Get("b"), Get("c"))))

I'm still not sure what you mean by "recursive" - to me, recursion is the
act of a function calling itself until some condition is met that markes
the end (or actually begin I think) of the recursion, like this:

def fac(n):
    if n == 1:
        return 1
    return n * fac(n-1)

Thats recursion.

The AST on the other hand has as much nodes as the expression denotes - each
subexpression is its own node. But that's true for your approach too -
after all, it has to be that way, otherwise you'd miss some part of the
expression :)

If you mean by recursion that the top-node is called for evaluation which
then delegates the evaluation to its children - well, that's unavoidable -
but also in both cases. As I mentioned before, the only difference I see is
the order of evaluation  - but that is invariant, as long as for all
expression's their respective sub-expressions are evaluated beforehand.

> If I upseted you or anybody here by un-properly used
> words, please forgive me. I always feel my english
> must be improved :)

I'm not upset - I feared you were :) And I perceive your english at beeing
pretty good. 

English isn't my native tongue either, so sometimes it might be that my
answers are shorter (and thus more likely percieved unfriendly) because its
difficult to express one's opininon.

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list