ag: folgendes verhalten wurde implementiert:
authorBernhard Urban <lewurm@gmail.com>
Wed, 31 Mar 2010 13:58:16 +0000 (15:58 +0200)
committerBernhard Urban <lewurm@gmail.com>
Wed, 31 Mar 2010 13:58:16 +0000 (15:58 +0200)
> 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
ag/symtable.c
ag/symtable.h

index c9b465aecb4355d8066031146a108f871d57ebcf..494e6dfbde43f9dbae68fae328bced2fa9912564 100644 (file)
@@ -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
index 590077d71cfc8321bdeca31b56eb9d265093b8dd..9c53557159fd9caf515e3167e51007db84bb9ec5 100755 (executable)
@@ -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);
index 4897a744277aba5b8a411e52a7f12c9554234c38..06aaffc79197789b64458d0e52d5664439ab72da 100755 (executable)
@@ -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