aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-08-01 21:52:08 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-08-01 21:52:08 -0400
commit3c0ca817145ad919dc6b92638edcffd739da7f8f (patch)
treebd4437510ed4fd8b8ec97e652e7e21fbfdb1c998
parentf1c02ce1c731d3b7cbe505764352012b7ab83887 (diff)
WIP Add sem_check files
Current (known) bugs: Checks id during var assignment
-rw-r--r--sem_check.c36
-rw-r--r--sem_check.h8
2 files changed, 44 insertions, 0 deletions
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 <assert.h>
+#include <stdio.h>
+
+#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