From 3c0ca817145ad919dc6b92638edcffd739da7f8f Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Thu, 1 Aug 2019 21:52:08 -0400 Subject: WIP Add sem_check files Current (known) bugs: Checks id during var assignment --- sem_check.c | 36 ++++++++++++++++++++++++++++++++++++ sem_check.h | 8 ++++++++ 2 files changed, 44 insertions(+) create mode 100644 sem_check.c create mode 100644 sem_check.h diff --git a/sem_check.c b/sem_check.c new file mode 100644 index 0000000..637d044 --- /dev/null +++ b/sem_check.c @@ -0,0 +1,36 @@ +#include +#include + +#include "node.h" +#include "scope.h" +#include "tree.h" +#include "y.tab.h" +#include "pc.h" +#include "sem_check.h" + +void check_id(s, n) +scope *s; +char *n; +{ + char buf[100]; + + if (scope_search(s, n)) { + snprintf(buf, 100, "\"%s\" already defined in scope...\n", n); + yyerror(buf); + } +} + +node* check_exists(s, n) +scope *s; +char *n; +{ + node *tmp; + char buf[100]; + + if(!(tmp = scope_search(s,n))) { + snprintf(buf, 100, "Cannot find \"%s\"\n", n); + yyerror(buf); + } + + return tmp; +} diff --git a/sem_check.h b/sem_check.h new file mode 100644 index 0000000..eef9e96 --- /dev/null +++ b/sem_check.h @@ -0,0 +1,8 @@ +#ifndef SEMCHECK_H +#define SEMCHECK_H + +void check_id(scope*, char*); + +node* check_exists(scope*, char*); + +#endif -- cgit v1.1