aboutsummaryrefslogtreecommitdiff
path: root/sem_check.c
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-08-17 15:47:08 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-08-17 15:47:08 -0400
commite1d044ff79638cf781816e8723fa78f1e9a7b34e (patch)
tree3d3c1e0bb1c1325a8fda319277c2cf97a6ec8f13 /sem_check.c
parent9508f73e75aa588e9639530c72e8f5ed2c02067c (diff)
Add Type checking if statement condition
Diffstat (limited to 'sem_check.c')
-rw-r--r--sem_check.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/sem_check.c b/sem_check.c
index d174bf8..7e6e338 100644
--- a/sem_check.c
+++ b/sem_check.c
@@ -123,13 +123,20 @@ ptree *t;
if (type == ARRAY - INT || type == ARRAY - REAL)
return ARRAY - type;
break;
+ case IF:
+ if (!(t->r && t->l))
+ yyerror("Incomplete parse tree\n");
+
+ if (t->l->ret_type != BOOL)
+ yyerror("If condition must be of type BOOL\n");
+ return 0;
+
default:
return -200;
snprintf(buf, 101, "Unknown tree node: %d...\n", t->type);
yyerror(buf);
}
-
return -1;
}