diff options
-rw-r--r-- | sem_check.c | 36 | ||||
-rw-r--r-- | sem_check.h | 8 |
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 |