ag: symtable renamed
authorBernhard Urban <lewurm@gmail.com>
Tue, 30 Mar 2010 11:57:04 +0000 (13:57 +0200)
committerBernhard Urban <lewurm@gmail.com>
Tue, 30 Mar 2010 11:57:04 +0000 (13:57 +0200)
ag/Makefile
ag/parser.y
ag/symbol_table.c [deleted file]
ag/symbol_table.h [deleted file]
ag/symtable.c [new file with mode: 0755]
ag/symtable.h [new file with mode: 0755]

index 236f3ae20919417268e1e38bc7d2d5fc968c981b..d4eff747f76f2944b8e14a53731d2712a38dcd0e 100644 (file)
@@ -1,7 +1,7 @@
 SHELL := bash
 NAME := ag
 CFLAGS := -ansi -pedantic -D_GNU_SOURCE
-OBJS := scanner.o parser.o symbol_table.o
+OBJS := scanner.o parser.o symtable.o
 TARGETS := parser.y scanner.lex
 
 all: $(NAME)
@@ -14,7 +14,7 @@ scanner.c: oxout.l
        @echo "  FLEX    $<"
        @flex -o$@ $<
 
-%.o: %.c parser.h symbol_table.h
+%.o: %.c parser.h symtable.h
        @echo "  CC      $<"
        @gcc -c $(CFLAGS) $< #-Wall
 
index ba76bb68add9970682d287e55d351701e1a36120..3d278fdd4619663ab50a3ce2f67ddf5052f055df 100644 (file)
@@ -2,7 +2,7 @@
        #include <stdio.h>
        #include <stdlib.h>
        #include <string.h>
-       #include "symbol_table.h"
+       #include "symtable.h"
 %}
 
 %start         Input
diff --git a/ag/symbol_table.c b/ag/symbol_table.c
deleted file mode 100755 (executable)
index 0c2df50..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include "symbol_table.h"
-
-struct symbol *new_tab(void)
-{
-       return SYMNULL;
-}
-
-struct symbol *clone_tab(struct symbol *tab)
-{
-       struct symbol *elm;
-       struct symbol *new_tabx;
-
-       elm = tab;
-       new_tabx = new_tab();
-       while(elm != SYMNULL) {
-               new_tabx = tab_add_symbol(new_tabx, elm->ident, elm->type, 0);
-               elm = elm->next;
-       }
-
-       return new_tabx;
-}
-
-struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check)
-{
-       struct symbol *elm;
-       struct symbol *new_elm;
-
-       if(tab_lookup(tab,ident) != SYMNULL) {
-               if(check) {
-                       fprintf(stderr, "Feld doppelt vorhanden: \"%s\"\n", ident);
-                       exit(3);
-               }
-               tab = tab_remove_symbol(tab, ident);
-       }
-       
-       new_elm = (struct symbol *) malloc(sizeof(struct symbol));
-       new_elm->next = SYMNULL;
-       new_elm->ident = strdup(ident);
-       new_elm->type = type;
-
-       if(tab == SYMNULL) {
-               return new_elm;
-       }
-
-       elm = tab;
-       while(elm->next != SYMNULL) {
-               elm = elm->next;
-       }
-       elm->next = new_elm;
-       
-       return tab;
-}
-
-struct symbol *tab_lookup(struct symbol *tab, char *ident)
-{
-       struct symbol *elm = tab;
-
-       if(tab == SYMNULL) {
-               return SYMNULL;
-       }
-       
-       if(strcmp(elm->ident, ident) == 0) {
-               return elm;
-       }
-       
-       while(elm->next != SYMNULL) {
-               elm = elm->next;
-               if(strcmp(elm->ident, ident) == 0) {
-                       return elm;
-               }
-       }
-
-       return SYMNULL;
-}
-
-struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check)
-{
-       struct symbol *elm = to_add;
-       struct symbol *new_tab = clone_tab(tab);
-       
-       while(elm != SYMNULL) {
-               new_tab = tab_add_symbol(new_tab, elm->ident, elm->type, check);
-               elm = elm->next;
-       }
-
-       return new_tab;
-}
-
-struct symbol *tab_remove_symbol(struct symbol *tab, char *ident)
-{
-       struct symbol *elm = tab;
-       struct symbol *previous_elm = SYMNULL;
-       struct symbol *new_elm;
-
-       if(tab == SYMNULL) {
-               return SYMNULL;
-       }
-
-       while(elm != SYMNULL) {
-               if(strcmp(elm->ident, ident) == 0) {
-                       if(previous_elm == SYMNULL) {
-                               new_elm = elm->next;
-                       } else {
-                               previous_elm->next = elm->next;
-                               new_elm = tab;
-                       }
-                       (void)free(elm->ident);
-                       (void)free(elm);
-                       return new_elm;
-               }
-               previous_elm = elm;
-               elm = elm->next;
-       }
-
-       return tab;
-}
-
-void check_variable(struct symbol *tab, char *ident)
-{
-       struct symbol *elm = tab_lookup(tab, ident);
-       if(elm != SYMNULL) {
-               if(elm->type != S_VAR) {
-                       fprintf(stderr, "Identifier ist keine Variable: \"%s\"\n", ident);
-                       exit(3);
-               }
-       } else {
-               fprintf(stderr, "Unbekannter Identifier: \"%s\"\n", ident);
-               exit(3);
-       }
-}
-
-void check_field(struct symbol *tab, char *ident)
-{
-       struct symbol *elm = tab_lookup(tab, ident);
-       if(elm != SYMNULL) {
-               if(elm->type != S_FIELD) {
-                       fprintf(stderr, "Identifier ist kein Feld: \"%s\"\n", ident);
-                       exit(3);
-               }
-       } else {
-               fprintf(stderr, "Unbekannter Identifier: \"%s\"\n", ident);
-               exit(3);
-       }
-}
-
diff --git a/ag/symbol_table.h b/ag/symbol_table.h
deleted file mode 100755 (executable)
index 63626b0..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef SYMBOL_TABLE_H
-#define SYMBOL_TABLE_H
-
-#define S_FIELD 0
-#define S_VAR 1
-
-#define SYMNULL (struct symbol *)NULL
-
-struct symbol {
-       char *ident;
-       struct symbol *next;
-       short type;
-};
-
-struct symbol *clone_tab(struct symbol *tab);
-struct symbol *new_tab(void);
-struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check);
-struct symbol *tab_lookup(struct symbol *tab, char *ident);
-struct symbol *tab_remove_symbol(struct symbol *tab, char *ident);
-struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check);
-void check_variable(struct symbol *tab, char *ident);
-void check_field(struct symbol *tab, char *ident);
-
-#endif
diff --git a/ag/symtable.c b/ag/symtable.c
new file mode 100755 (executable)
index 0000000..4195720
--- /dev/null
@@ -0,0 +1,148 @@
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "symtable.h"
+
+struct symbol *new_tab(void)
+{
+       return SYMNULL;
+}
+
+struct symbol *clone_tab(struct symbol *tab)
+{
+       struct symbol *elm;
+       struct symbol *new_tabx;
+
+       elm = tab;
+       new_tabx = new_tab();
+       while(elm != SYMNULL) {
+               new_tabx = tab_add_symbol(new_tabx, elm->ident, elm->type, 0);
+               elm = elm->next;
+       }
+
+       return new_tabx;
+}
+
+struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check)
+{
+       struct symbol *elm;
+       struct symbol *new_elm;
+
+       if(tab_lookup(tab,ident) != SYMNULL) {
+               if(check) {
+                       fprintf(stderr, "Feld doppelt vorhanden: \"%s\"\n", ident);
+                       exit(3);
+               }
+               tab = tab_remove_symbol(tab, ident);
+       }
+       
+       new_elm = (struct symbol *) malloc(sizeof(struct symbol));
+       new_elm->next = SYMNULL;
+       new_elm->ident = strdup(ident);
+       new_elm->type = type;
+
+       if(tab == SYMNULL) {
+               return new_elm;
+       }
+
+       elm = tab;
+       while(elm->next != SYMNULL) {
+               elm = elm->next;
+       }
+       elm->next = new_elm;
+       
+       return tab;
+}
+
+struct symbol *tab_lookup(struct symbol *tab, char *ident)
+{
+       struct symbol *elm = tab;
+
+       if(tab == SYMNULL) {
+               return SYMNULL;
+       }
+       
+       if(strcmp(elm->ident, ident) == 0) {
+               return elm;
+       }
+       
+       while(elm->next != SYMNULL) {
+               elm = elm->next;
+               if(strcmp(elm->ident, ident) == 0) {
+                       return elm;
+               }
+       }
+
+       return SYMNULL;
+}
+
+struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check)
+{
+       struct symbol *elm = to_add;
+       struct symbol *new_tab = clone_tab(tab);
+       
+       while(elm != SYMNULL) {
+               new_tab = tab_add_symbol(new_tab, elm->ident, elm->type, check);
+               elm = elm->next;
+       }
+
+       return new_tab;
+}
+
+struct symbol *tab_remove_symbol(struct symbol *tab, char *ident)
+{
+       struct symbol *elm = tab;
+       struct symbol *previous_elm = SYMNULL;
+       struct symbol *new_elm;
+
+       if(tab == SYMNULL) {
+               return SYMNULL;
+       }
+
+       while(elm != SYMNULL) {
+               if(strcmp(elm->ident, ident) == 0) {
+                       if(previous_elm == SYMNULL) {
+                               new_elm = elm->next;
+                       } else {
+                               previous_elm->next = elm->next;
+                               new_elm = tab;
+                       }
+                       (void)free(elm->ident);
+                       (void)free(elm);
+                       return new_elm;
+               }
+               previous_elm = elm;
+               elm = elm->next;
+       }
+
+       return tab;
+}
+
+void check_variable(struct symbol *tab, char *ident)
+{
+       struct symbol *elm = tab_lookup(tab, ident);
+       if(elm != SYMNULL) {
+               if(elm->type != S_VAR) {
+                       fprintf(stderr, "Identifier ist keine Variable: \"%s\"\n", ident);
+                       exit(3);
+               }
+       } else {
+               fprintf(stderr, "Unbekannter Identifier: \"%s\"\n", ident);
+               exit(3);
+       }
+}
+
+void check_field(struct symbol *tab, char *ident)
+{
+       struct symbol *elm = tab_lookup(tab, ident);
+       if(elm != SYMNULL) {
+               if(elm->type != S_FIELD) {
+                       fprintf(stderr, "Identifier ist kein Feld: \"%s\"\n", ident);
+                       exit(3);
+               }
+       } else {
+               fprintf(stderr, "Unbekannter Identifier: \"%s\"\n", ident);
+               exit(3);
+       }
+}
+
diff --git a/ag/symtable.h b/ag/symtable.h
new file mode 100755 (executable)
index 0000000..92bfc86
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef SYMTABLE_H
+#define SYMTABLE_H
+
+#define S_FIELD 0
+#define S_VAR 1
+
+#define SYMNULL (struct symbol *)NULL
+
+struct symbol {
+       char *ident;
+       struct symbol *next;
+       short type;
+};
+
+struct symbol *clone_tab(struct symbol *tab);
+struct symbol *new_tab(void);
+struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check);
+struct symbol *tab_lookup(struct symbol *tab, char *ident);
+struct symbol *tab_remove_symbol(struct symbol *tab, char *ident);
+struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check);
+void check_variable(struct symbol *tab, char *ident);
+void check_field(struct symbol *tab, char *ident);
+
+#endif