From e1d044ff79638cf781816e8723fa78f1e9a7b34e Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sat, 17 Aug 2019 15:47:08 -0400 Subject: Add Type checking if statement condition --- scope.c | 1 + sem_check.c | 9 ++++++++- tree.c | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scope.c b/scope.c index eca78cd..f093b82 100644 --- a/scope.c +++ b/scope.c @@ -5,6 +5,7 @@ #include "node.h" #include "scope.h" +#include "pc.h" scope* mkscope() { 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; } diff --git a/tree.c b/tree.c index ee4bb8e..de9a0f5 100644 --- a/tree.c +++ b/tree.c @@ -5,6 +5,8 @@ #include "node.h" #include "tree.h" +#include "scope.h" +#include "sem_check.h" #include "y.tab.h" #include "pc.h" -- cgit v1.1