ag: refactor fun
authorBernhard Urban <lewurm@gmail.com>
Thu, 22 Apr 2010 13:09:17 +0000 (15:09 +0200)
committerBernhard Urban <lewurm@gmail.com>
Thu, 22 Apr 2010 13:09:17 +0000 (15:09 +0200)
ag/parser.y
ag/symtable.c
ag/symtable.h

index d7cdf4a8b9ca590a25669c49b5b554fbc42d2717..dbd4e2412f340410fb84c702279515e8ba76f387 100644 (file)
@@ -6,8 +6,7 @@
 %}
 
 %start Input
-%token STRUCT END METHOD VAR IF THEN ELSE WHILE DO RETURN NOT OR THIS
-%token IDENT NUM ASSIGN
+%token STRUCT END METHOD VAR IF THEN ELSE WHILE DO RETURN NOT OR THIS IDENT NUM ASSIGN
 
 @macro xxputsin(xx,)
        @i xx = @Statement.sin@;
@@ -32,7 +31,7 @@
 Input:
          Program
          @{
-           @i @Program.f@ = new_tab();
+           @i @Program.f@ = tab_new();
          @}
        ;
 
@@ -73,7 +72,7 @@ Parms:
 
        |
          @{
-           @i @Parms.f@ = new_tab();
+           @i @Parms.f@ = tab_new();
          @}
        ;
 
@@ -85,7 +84,7 @@ FeldID:
 
        |
          @{
-           @i @FeldID.f@ = new_tab();
+           @i @FeldID.f@ = tab_new();
          @}
        ;
 
@@ -109,7 +108,9 @@ Statement:
 
        | VAR IDENT ASSIGN Expr
          @{
-               @i @Statement.sout@ = tab_add_symbol(clone_tab(@Statement.sin@), @IDENT.name@, S_VAR, 1);
+               /* tab_clone ist hier noetig, vgl. folgendes statement
+                * > var x := x - 1; */
+               @i @Statement.sout@ = tab_add_symbol(tab_clone(@Statement.sin@), @IDENT.name@, S_VAR, 1);
                xxputsin(@Expr.s@,)
          @}
 
index 8c175e5e0421d1e15cd31e1c81f50fe560dc4402..850c1b08388b9252a5dac9f54ee674c0f256bf11 100755 (executable)
@@ -5,32 +5,29 @@
 
 #define DD
 
-struct symbol *new_tab(void)
+struct symbol *tab_new(void)
 {
        return SYMNULL;
 }
 
-struct symbol *clone_tab(struct symbol *tab)
+struct symbol *tab_clone(struct symbol *tab)
 {
-       struct symbol *elm;
-       struct symbol *new_tabx;
+       struct symbol *elm = tab;
+       struct symbol *ntab = tab_new();
 #ifdef DD
-       printf("clone_tab: tab(%08X)\n", tab);
+       printf("tab_clone: tab(%08X)\n", tab);
 #endif
 
-       elm = tab;
-       new_tabx = new_tab();
        while(elm != SYMNULL) {
-               new_tabx = tab_add_symbol(new_tabx, elm->ident, elm->type, 0);
+               ntab = tab_add_symbol(ntab, elm->ident, elm->type, 0);
                elm = elm->next;
        }
-
-       return new_tabx;
+       return ntab;
 }
 
 struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check)
 {
-       struct symbol *elm;
+       struct symbol *elm = tab;
        struct symbol *new_elm;
 #ifdef DD
        printf("tab_add_symbol: tab(%08X), ident(%s), type(%i), check(%i)\n", tab, ident, type, check);
@@ -54,7 +51,6 @@ struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short
                return new_elm;
        }
 
-       elm = tab;
        while(elm->next != SYMNULL) {
                elm = elm->next;
        }
@@ -84,17 +80,17 @@ struct symbol *tab_lookup(struct symbol *tab, char *ident, short type)
 struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check)
 {
        struct symbol *elm = to_add;
-       struct symbol *new_tab = clone_tab(tab);
+       struct symbol *ntab = tab_clone(tab);
 #ifdef DD
-       printf("tab_merge: tab(%08X), to_add(%08X), check(%i), new_tab(%08X)\n", tab, to_add, check, new_tab);
+       printf("tab_merge: tab(%08X), to_add(%08X), check(%i), ntab(%08X)\n", tab, to_add, check, ntab);
 #endif
        
        while(elm != SYMNULL) {
-               new_tab = tab_add_symbol(new_tab, elm->ident, elm->type, check);
+               ntab = tab_add_symbol(ntab, elm->ident, elm->type, check);
                elm = elm->next;
        }
 
-       return new_tab;
+       return ntab;
 }
 
 struct symbol *tab_remove_symbol(struct symbol *tab, char *ident, short type)
@@ -134,6 +130,8 @@ void check(struct symbol *tab, char *ident, short type)
                }
        }
 
+       /* keine passende variable gefunden?
+        * => vllt gibt es ja ein passenden feldnamen */
        elm = tab_lookup(tab, ident, S_FIELD);
        if(elm == SYMNULL) {
                fprintf(stderr, "Unbekannter Identifier: \"%s\"\n", ident);
index 06aaffc79197789b64458d0e52d5664439ab72da..df7fa5a6561ed95135d5dc76f0fc0e3059f1dfc9 100755 (executable)
@@ -12,8 +12,8 @@ struct symbol {
        short type;
 };
 
-struct symbol *clone_tab(struct symbol *tab);
-struct symbol *new_tab(void);
+struct symbol *tab_clone(struct symbol *tab);
+struct symbol *tab_new(void);
 struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check);
 struct symbol *tab_lookup(struct symbol *tab, char *ident, short type);
 struct symbol *tab_remove_symbol(struct symbol *tab, char *ident, short type);