How is Python designed?

Limin Fu fulimin_yuan at yahoo.com
Mon Dec 6 16:24:14 EST 2004


Hi,

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

You are right. The Yuan interpreter scans the tokens
resulted from lexical analysis and matches them to the
syntax patterns. There are 3 basic patterns defined in
Yuan: arithmetic "a*b+c", chain (as I called it)
"objs[i]->func()" and regular expression "/\d*[abc]/",
each of which is represented by a class. And the other
patterns are a combination of these 3 basic pattern,
e.g. array enumeration "a=[1,a+1,func()]" etc. There
are functions responsible to parse the token patterns
to phrase objects. After all phrase objects are
generated, logical and loop controls are checked, so
that each phrase object "knows" if it should "step to"
the next phrase object or "jump to" another one when
it is executed. In this technique, indeed, checking
patterns is a little complicated. In Yuan this part is
not optimally implemented, somethings have to be
improved or changed. 

> 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.

I supposed you would have done like:
class node{
...
char oper;
node *left,*right;
void compute();
};
void node::compute()
{
   if(left) left->compute();
   if(right) right->compute();
   if(oper=='+'){
      ....
   }else if(...){
      ....
   }
}
This is a kind of recursive evaluation of arithmetic
tree. Now I believe that's not what you have used.

> If you mean by recursion that the top-node is called
> for evaluation which
> then delegates the evaluation to its children -

Ah, yes. That's exactly what I mean.

> well, that's unavoidable -

That's avoidable, using depth first seach.

> 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.

It seemed to me that it made much difference in
efficiency so that I reimplemented it by depth-first
search. Maybe because I didn't implement the recursive
evaluation properly :), I will check.

> 
> I'm not upset - I feared you were :) And I perceive

Ok, since non of us is upseted, let's forget it :)

Best,

Limin




		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail



More information about the Python-list mailing list