#include "syntax_tree.h" #include "y.tab.h" /* defined in syntax_tree.c */ extern Obj pushFunc(char *); extern void popScope(); extern Obj pushGvar(char *); extern Obj pushGarr(char *,int); extern Obj pushLvar(char *); extern Obj pushLarr(char *,int); extern Obj getObj(char *); Tree bindObj(Tree t) { Tree s,v; Obj o; if (t==NUL) return NUL; switch (t->type) { case FUNC_DEF: t->left->obj = o = pushFunc(t->left->name); for (s = t->right; s!=NUL; s = s->right) s->left->obj = pushLvar(s->left->name); o->args = o->size; bindObj(t->third); popScope(); break; case GVAR_DECL: for (s = t->left; s!=NUL; s = s->right) { v = s->left; switch (v->type) { case SCALAR: v->left->obj = pushGvar(v->left->name); break; case ARRAY: v->left->obj = pushGarr(v->left->name, v->right->num); } } break; case LVAR_DECL: for (s = t->left; s!=NUL; s = s->right) { v = s->left; switch (v->type) { case SCALAR: v->left->obj = pushLvar(v->left->name); break; case ARRAY: v->left->obj = pushLarr(v->left->name, v->right->num); } } break; case SYM: t->obj = getObj(t->name); break; default: bindObj(t->left); bindObj(t->right); bindObj(t->third); } return t; }