@attributes { struct symbol *symbols; } Funcdef Stats Bool Expr Call Lexpr Field Term Plusterm Malterm Bterm Orterm Exprs
@attributes { struct symbol *in_symbols; struct symbol *out_symbols; } Stat
-@traversal @postorder t
+@traversal @postorder c
%%
Program: Funcdef ';' Program
@{
- @i @Program.fields@ = @Program.1.fields@;
+ @i @Program.0.fields@ = @Program.1.fields@;
@}
| Structdef ';' Program
@{
- @i @Program.fields@ = tab_merge(@Structdef.fields@, @Program.1.fields@, 1);
+ @i @Program.0.fields@ = tab_merge(@Structdef.fields@, @Program.1.fields@, 1);
@i @Program.1.symbols@ = @Program.0.symbols@;
@}
;
Ids: ID Ids
- @{ @i @Ids.fields@ = tab_add_symbol(@Ids.1.fields@, @ID.name@, S_FIELD, 1); @}
+ @{ @i @Ids.0.fields@ = tab_add_symbol(@Ids.1.fields@, @ID.name@, S_FIELD, 1); @}
|
@{ @i @Ids.fields@ = new_tab(); @}
;
Pars: Pars ',' ID
- @{ @i @Pars.pars@ = tab_add_symbol(@Pars.1.pars@, @ID.name@, S_VAR, 0); @}
+ @{ @i @Pars.0.pars@ = tab_add_symbol(@Pars.1.pars@, @ID.name@, S_VAR, 0); @}
| ID
@{ @i @Pars.pars@ = tab_add_symbol(new_tab(), @ID.name@, S_VAR, 0); @}
Stats: Stat ';' Stats
@{
- @i @Stat.in_symbols@ = @Stats.symbols@;
+ @i @Stat.in_symbols@ = @Stats.0.symbols@;
@i @Stats.1.symbols@ = @Stat.out_symbols@;
@}
| IF Bool THEN Stats ELSE Stats END
@{
@i @Bool.symbols@ = @Stat.in_symbols@;
- @i @Stats.symbols@ = @Stat.in_symbols@;
+ @i @Stats.0.symbols@ = @Stat.in_symbols@;
@i @Stats.1.symbols@ = @Stat.in_symbols@;
@i @Stat.out_symbols@ = @Stat.in_symbols@;
@}
;
Lexpr: ID
- @{ @t check_variable(@Lexpr.symbols@, @ID.name@); @}
+ @{ @c check_variable(@Lexpr.symbols@, @ID.name@); @}
| Field
;
Term: '(' Expr ')'
| ID
- @{ @t check_variable(@Term.symbols@, @ID.name@); @}
+ @{ @c check_variable(@Term.symbols@, @ID.name@); @}
| NUM
| Call
;
Field: Term '.' ID
- @{ @t check_field(@Field.symbols@, @ID.name@); @}
+ @{ @c check_field(@Field.symbols@, @ID.name@); @}
;
struct symbol *elm;
struct symbol *new_elm;
- if(tab_lookup(tab,ident) != SYMNULL) {
+ if(tab_lookup(tab, ident) != SYMNULL) {
if(check) {
fprintf(stderr, "Feld doppelt vorhanden: \"%s\"\n", ident);
exit(3);
+ } else {
+ tab = tab_remove_symbol(tab, ident);
}
- tab = tab_remove_symbol(tab, ident);
}
new_elm = (struct symbol *) malloc(sizeof(struct symbol));
if(tab == SYMNULL) {
return SYMNULL;
}
-
- if(strcmp(elm->ident, ident) == 0) {
- return elm;
- }
-
- while(elm->next != SYMNULL) {
- elm = elm->next;
+
+ do {
if(strcmp(elm->ident, ident) == 0) {
return elm;
}
- }
+ elm = elm->next;
+ } while(elm != SYMNULL);
return SYMNULL;
}
{
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;
+ tab = elm->next;
} else {
previous_elm->next = elm->next;
- new_elm = tab;
}
(void)free(elm->ident);
(void)free(elm);
- return new_elm;
+ break;
}
previous_elm = elm;
elm = elm->next;