aboutsummaryrefslogtreecommitdiff
path: root/sem_check.c
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 /sem_check.c
parentf1c02ce1c731d3b7cbe505764352012b7ab83887 (diff)
WIP Add sem_check files
Current (known) bugs: Checks id during var assignment
Diffstat (limited to 'sem_check.c')
-rw-r--r--sem_check.c36
1 files changed, 36 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;
+}