aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-08-17 15:46:16 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-08-17 15:46:16 -0400
commit9508f73e75aa588e9639530c72e8f5ed2c02067c (patch)
tree7b4f0ece4855220f6117bb57de0466c407d870ee
parent1ff4c71e7a5140cd045a9483a76d667bd6837744 (diff)
Add if statements to tree print
Removes printing tree during return type setting
-rw-r--r--tree.c116
1 files changed, 38 insertions, 78 deletions
diff --git a/tree.c b/tree.c
index 11c08d4..ee4bb8e 100644
--- a/tree.c
+++ b/tree.c
@@ -86,12 +86,40 @@ ptree *list;
void set_ret_type(t)
ptree *t;
{
- if (!t){
+ if (!t)
return;
- }
-
- switch (t->type) {
+
+ set_ret_type(t->l);
+ set_ret_type(t->r);
+ t->ret_type = check_ret_type(t);
+
+ return;
+}
+
+
+/*PRINT FUNCS*/
+
+void print_tree(t)
+ptree *t;
+{
+ fprintf(stderr, "\n\nTREE\n"
+ "==========================================================\n");
+ aux_tree_print(t, 0);
+ fprintf(stderr,
+ "**********************************************************\n");
+ return;
+}
+
+void aux_tree_print(t, spaces)
+ptree* t;
+int spaces;
+{
+ int i;
+ if ( t ) {
+ for (i = 0; i < spaces; i++)
+ fprintf(stderr," ");
+ switch (t->type) {
case ADDOP:
fprintf(stderr, "[ADDOP]");
break;
@@ -131,80 +159,12 @@ ptree *t;
case ASSIGNOP:
fprintf(stderr, "[ASSIGN]");
break;
- default:
- fprintf(stderr, "\t%d", t->type);
- yyerror("Error in tree_print");
- }
- set_ret_type(t->l);
- set_ret_type(t->r);
- t->ret_type = check_ret_type(t);
-
- return;
-}
-
-
-/*PRINT FUNCS*/
-
-void print_tree(t)
-ptree *t;
-{
- fprintf(stderr, "\n\nTREE\n"
- "==========================================================\n");
- aux_tree_print(t, 0);
- fprintf(stderr,
- "**********************************************************\n");
- return;
-}
-
-void aux_tree_print(t, spaces)
-ptree* t;
-int spaces;
-{
- int i;
- if ( t ) {
- for (i = 0; i < spaces; i++)
- fprintf(stderr," ");
- switch (t->type) {
-
- case ADDOP:
- fprintf(stderr, "[ADDOP]");
- break;
- case MULOP:
- fprintf(stderr, "[MULOP]");
- break;
- case RELOP:
- fprintf(stderr, "[RELOP]");
- break;
- case NOT:
- fprintf(stderr, "[NOT]");
- break;
- case ARRAY_ACCESS:
- fprintf(stderr, "[ARRAY ACCESS]");
- break;
- case LIST:
- fprintf(stderr, "[LIST]");
- break;
- case ID:
- if (t->r && t->r->attr.nval)
- fprintf(stderr, "[ID: %s %s]",
- t->r->attr.nval->name,
- pretty_type(
- t->attr.nval->var_type));
- else
- fprintf(stderr, "[ID: %s %s]",
- t->attr.nval->name,
- pretty_type(
- t->attr.nval->var_type));
- break;
- case INUM:
- fprintf(stderr, "[INUM: %d]", t->attr.ival);
- break;
- case RNUM:
- fprintf(stderr, "[RNUM: %f]", t->attr.rval);
- break;
- case ASSIGNOP:
- fprintf(stderr, "[ASSIGN]");
- break;
+ case IF:
+ fprintf(stderr, "[IF]");
+ break;
+ case THEN:
+ fprintf(stderr, "[THEN]");
+ break;
default:
fprintf(stderr, "\t%d", t->type);
yyerror("Error in tree_print");