From 394a3c955a5b9a544355c52a0243f0da61998c83 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Wed, 31 Mar 2010 15:58:16 +0200 Subject: [PATCH] ag: folgendes verhalten wurde implementiert: > struct a b end; > method f() > var z := a; > end; ist deswegen gueltig, da a zu this.a wird, und this eine struktur sein kann. aber auch das ist gueltig: > struct a b end; > method f(a) > var z := a; > end; hier soll der parameter bzw. die variable 'a' den vorang haben. --- ag/parser.y | 6 +++--- ag/symtable.c | 25 +++++++++++-------------- ag/symtable.h | 3 +-- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/ag/parser.y b/ag/parser.y index c9b465a..494e6df 100644 --- a/ag/parser.y +++ b/ag/parser.y @@ -158,7 +158,7 @@ Statement: Lexpr: IDENT @{ - @c check_variable(@Lexpr.s@, @IDENT.name@); + @c check(@Lexpr.s@, @IDENT.name@, S_VAR); @} | Feld @@ -166,7 +166,7 @@ Lexpr: Feld: Term '.' IDENT @{ - @c check_field(@Feld.s@, @IDENT.name@); + @c check(@Feld.s@, @IDENT.name@, S_FIELD); @} ; @@ -202,7 +202,7 @@ Term: | THIS | IDENT @{ - @c check_variable(@Term.s@, @IDENT.name@); + @c check(@Term.s@, @IDENT.name@, S_VAR); @} | Feld diff --git a/ag/symtable.c b/ag/symtable.c index 590077d..9c53557 100755 --- a/ag/symtable.c +++ b/ag/symtable.c @@ -5,8 +5,6 @@ #define DD -static void check_gen(struct symbol *tab, char *ident, short type); - struct symbol *new_tab(void) { return SYMNULL; @@ -122,22 +120,21 @@ struct symbol *tab_remove_symbol(struct symbol *tab, char *ident, short type) return tab; } -void check_variable(struct symbol *tab, char *ident) -{ - check_gen(tab, ident, S_VAR); -} - -void check_field(struct symbol *tab, char *ident) -{ - check_gen(tab, ident, S_FIELD); -} - -static void check_gen(struct symbol *tab, char *ident, short type) +void check(struct symbol *tab, char *ident, short type) { - struct symbol *elm = tab_lookup(tab, ident, type); + struct symbol *elm; #ifdef DD printf("check_variable: tab(%08X), ident(%s), type(%i), elm(%08X)\n", tab, ident, type, elm); #endif + + if(type == S_VAR) { + elm = tab_lookup(tab, ident, type); + if(elm != SYMNULL) { + return; + } + } + + elm = tab_lookup(tab, ident, S_FIELD); if(elm == SYMNULL) { fprintf(stderr, "Unbekannter Identifier: \"%s\"\n", ident); exit(3); diff --git a/ag/symtable.h b/ag/symtable.h index 4897a74..06aaffc 100755 --- a/ag/symtable.h +++ b/ag/symtable.h @@ -18,7 +18,6 @@ struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short struct symbol *tab_lookup(struct symbol *tab, char *ident, short type); struct symbol *tab_remove_symbol(struct symbol *tab, char *ident, short type); 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); +void check(struct symbol *tab, char *ident, short type); #endif -- 2.25.1