Tree E();
Tree T();
Tree F();
Tree C();
Tree R();
int D();
Tree mkleaf(float val) {
Tree p = (Tree)malloc(sizeof(TNode));
p->tag = real;
p->tnt.value = val;
return p;
}
Tree mknode(NodeType tag, Tree left, Tree right) {
Tree p = (Tree)malloc(sizeof(TNode));
p->tag = tag;
p->tnt.child.left = left;
p->tnt.child.right = right;
return p;
}
void print(int dent, Tree t) {
int i = dent;
if(t) {
if(t->tag != real) print(dent+1, t->tnt.child.right);
while(i--) printf(" ");
switch(t->tag) {
case real: printf("%f\n", t->tnt.value); break;
case add : printf("%c\n", '+'); break;
case sub : printf("%c\n", '-'); break;
case mul : printf("%c\n", '*'); break;
case di : printf("%c\n", '/'); break;
case po : printf("%c\n", '^'); break;
}
if(t->tag != real) print(dent+1, t->tnt.child.left);
}
}
当前数 当前符 数栈 符栈 运算
b +0 a n
c *0 a,b +0 n
d -1 a,b,c +0, *0 n
e -0 a,b,c,d +0, *0, -1 y
e -0 a,b,-(c)(d) +0, *0 y
e -0 a,*(b)(-(c)(d)) +0 y
e -0 +(a)(*(b)(-(c)(d))) n
f /0 +(a)(*(b)(-(c)(d))), e -0 n
+(a)(*(b)(-(c)(d))), e,f -0, /0 y
+(a)(*(b)(-(c)(d))), /(e)(f) -0 y
-(+(a)(*(b)(-(c)(d))))(/(e)(f))