From 389c2765afebb0b6112493e53117405488a4f3f1 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Thu, 29 Aug 2019 11:57:55 -0400 Subject: Add for loop type checking --- sem_check.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/sem_check.c b/sem_check.c index 88f41ad..773c70a 100644 --- a/sem_check.c +++ b/sem_check.c @@ -141,7 +141,27 @@ ptree *t; yyerror("If condition must be of type BOOL\n"); return 1; case FOR: - /*TODO add for type checking after parsing is correct*/ + /* + FOR (0) + / \ + TD(0) STATEMENT(0) + / \ + ASSIGNOP(0) INUM(INT) + */ + if (!(t->r && t->l)) + yyerror("Missing nodes\n"); + if (t->l->ret_type == 1 && t->r->ret_type == 1) + return 1; + snprintf(buf, 100, "Incorrect types in for statement...\n"); + break; + case TO: + case DT: + if (!(t->r && t->l)) + yyerror("Missing nodes\n"); + + if (t->l->ret_type == 1 && t->r->ret_type == INT) + return 1; + snprintf(buf, 100, "Incorrect types HERE...\n"); break; default: return -200; -- cgit v1.1