aboutsummaryrefslogtreecommitdiff
path: root/tree.c
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-07-27 12:40:16 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-07-27 12:40:16 -0400
commite9ae811ffaa08caef0acca643ca1e7a1ff72396f (patch)
treed43fd26e134f91e3814f48506234396fbc199453 /tree.c
parent596bc33348e2daa5af8a0168f015e850aeccf0fc (diff)
Add update types during declaration
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/tree.c b/tree.c
index 0301ec3..3a2afcf 100644
--- a/tree.c
+++ b/tree.c
@@ -27,7 +27,8 @@ ptree* mkid(str)
char *str;
{
ptree *p = mktree(ID, NULL, NULL);
- p->attr.sval = strdup(str); /* memory leak? double strdup*/
+ p->attr.nval = malloc(sizeof(node)); /*TODO fix hacky node create*/
+ p->attr.nval->name = strdup(str); /* memory leak? double strdup*/
return p;
}
@@ -56,6 +57,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 +119,7 @@ int spaces;
fprintf(stderr, "[LIST]");
break;
case ID:
- fprintf(stderr, "[ID: %s]", t->attr.sval);
+ fprintf(stderr, "[ID: %s %d]", t->attr.nval->name, t->attr.nval->var_type);
break;
case INUM:
fprintf(stderr, "[INUM: %d]", t->attr.ival);