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);
39 new_elm = (struct symbol *) malloc(sizeof(struct symbol));
40 new_elm->next = SYMNULL;
41 new_elm->ident = strdup(ident);
49 while(elm->next != SYMNULL) {
57 struct symbol *tab_lookup(struct symbol *tab, char *ident)
59 struct symbol *elm = tab;
65 if(strcmp(elm->ident, ident) == 0) {
69 while(elm->next != SYMNULL) {
71 if(strcmp(elm->ident, ident) == 0) {
79 struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check)
81 struct symbol *elm = to_add;
82 struct symbol *new_tab = clone_tab(tab);
84 while(elm != SYMNULL) {
85 new_tab = tab_add_symbol(new_tab, elm->ident, elm->type, check);
92 struct symbol *tab_remove_symbol(struct symbol *tab, char *ident)
94 struct symbol *elm = tab;
95 struct symbol *previous_elm = SYMNULL;
96 struct symbol *new_elm;
102 while(elm != SYMNULL) {
103 if(strcmp(elm->ident, ident) == 0) {
104 if(previous_elm == SYMNULL) {
107 previous_elm->next = elm->next;
110 (void)free(elm->ident);
121 void check_variable(struct symbol *tab, char *ident)
123 struct symbol *elm = tab_lookup(tab, ident);
125 if(elm->type != S_VAR) {
126 fprintf(stderr, "Identifier ist keine Variable: \"%s\"\n", ident);
130 fprintf(stderr, "Unbekannter Identifier: \"%s\"\n", ident);
135 void check_field(struct symbol *tab, char *ident)
137 struct symbol *elm = tab_lookup(tab, ident);
139 if(elm->type != S_FIELD) {
140 fprintf(stderr, "Identifier ist kein Feld: \"%s\"\n", ident);
144 fprintf(stderr, "Unbekannter Identifier: \"%s\"\n", ident);