diff options
-rw-r--r-- | pc.y | 5 | ||||
-rw-r--r-- | tree.c | 26 | ||||
-rw-r--r-- | tree.h | 2 |
3 files changed, 28 insertions, 5 deletions
@@ -118,10 +118,7 @@ id_list var_declarations :var_declarations VAR id_list ':' type ';' { - ptree *tmp; - for(tmp = $3; tmp; tmp = tmp->l) - tmp->type = $5; - + update_type_info($3, $5); } |/*empty*/ ; @@ -56,6 +56,30 @@ ptree *l, *r; return p; } +void update_type_info(list, type) +int type; +ptree *list; +{ + assert(list); + while (list->r && list->r->type == ID) { + /*Set type of right child through list*/ + list->r->attr.nval->var_type = type; + + if (list->l) { + if (list->l->type == LIST) { + list = list->l; + continue; /*Continue down list*/ + } else if (list->l->type == ID) + /*Set type of first declared ID (only left node in LIST)*/ + list->l->attr.nval->var_type = type; + } + return; /*At _end_ of list (did not continue)*/ + } +} + + +/*PRINT FUNCS*/ + void print_tree(t) ptree *t; { @@ -94,7 +118,7 @@ int spaces; fprintf(stderr, "[LIST]"); break; case ID: - fprintf(stderr, "[ID: %s]", t->attr.nval->name); + fprintf(stderr, "[ID: %s %d]", t->attr.nval->name, t->attr.nval->var_type); break; case INUM: fprintf(stderr, "[INUM: %d]", t->attr.ival); @@ -24,4 +24,6 @@ ptree* mkinum(int); ptree* mkrnum(float); ptree* mkop(int, int, ptree*, ptree*); +void update_type_info(ptree*, int); + #endif |