6 struct symbol *new_tab(void)
11 struct symbol *clone_tab(struct symbol *tab)
14 struct symbol *new_tabx;
18 while(elm != SYMNULL) {
19 new_tabx = tab_add_symbol(new_tabx, elm->ident, elm->type, 0);
26 struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check)
29 struct symbol *new_elm;
31 if(tab_lookup(tab, ident) != SYMNULL) {
33 fprintf(stderr, "Feld doppelt vorhanden: \"%s\"\n", ident);
36 tab = tab_remove_symbol(tab, ident);
40 new_elm = (struct symbol *) malloc(sizeof(struct symbol));
41 new_elm->next = SYMNULL;
42 new_elm->ident = strdup(ident);
50 while(elm->next != SYMNULL) {
58 struct symbol *tab_lookup(struct symbol *tab, char *ident)
60 struct symbol *elm = tab;
67 if(strcmp(elm->ident, ident) == 0) {
71 } while(elm != SYMNULL);
76 struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check)
78 struct symbol *elm = to_add;
79 struct symbol *new_tab = clone_tab(tab);
81 while(elm != SYMNULL) {
82 new_tab = tab_add_symbol(new_tab, elm->ident, elm->type, check);
89 struct symbol *tab_remove_symbol(struct symbol *tab, char *ident)
91 struct symbol *elm = tab;
92 struct symbol *previous_elm = SYMNULL;
94 while(elm != SYMNULL) {
95 if(strcmp(elm->ident, ident) == 0) {
96 if(previous_elm == SYMNULL) {
99 previous_elm->next = elm->next;
101 (void)free(elm->ident);
112 void check_variable(struct symbol *tab, char *ident)
114 struct symbol *elm = tab_lookup(tab, ident);
116 if(elm->type != S_VAR) {
117 fprintf(stderr, "Identifier ist keine Variable: \"%s\"\n", ident);
121 fprintf(stderr, "Unbekannter Identifier: \"%s\"\n", ident);
126 void check_field(struct symbol *tab, char *ident)
128 struct symbol *elm = tab_lookup(tab, ident);
130 if(elm->type != S_FIELD) {
131 fprintf(stderr, "Identifier ist kein Feld: \"%s\"\n", ident);
135 fprintf(stderr, "Unbekannter Identifier: \"%s\"\n", ident);