codeb: minimale 'IF expr THEN statseq END' implementierung
[uebersetzerbau-ss10.git] / ag / parser.y
index 7df16d2f1ea6c67f299a0b07c0e5c1fa84366bbf..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@;
 @end
 
 @autoinh s
-/* f .. fields
- * s .. symbols  */
 @attributes { char *name; } IDENT
-@attributes { struct symbol *f; struct symbol *s; } Program
-@attributes { struct symbol *f; } FeldID Structdef Parms
-@attributes { struct symbol *s; } Methoddef Statseq Lexpr Expr Minusterm Multerm Orterm
-Term Exprs Feld
+@attributes { struct symbol *f; } FeldID Parms Structdef Program
+@attributes { struct symbol *s; } Methoddef Statseq Lexpr Expr Minusterm Multerm Orterm Term Exprs Feld
 @attributes { struct symbol *sin; struct symbol *sout; } Statement
 
 @traversal @postorder c
@@ -36,25 +31,22 @@ Term Exprs Feld
 Input:
          Program
          @{
-               @i @Program.s@ = @Program.f@;
+           @i @Program.f@ = tab_new();
          @}
        ;
 
 Program:
          Methoddef ';' Program
          @{
-           @i @Program.0.f@ = @Program.1.f@;
+           @i @Methoddef.s@ = @Program.0.f@;
+           @i @Program.1.f@ = @Program.0.f@;
          @}
-         
+
        | Structdef ';' Program
          @{
-           @i @Program.0.f@ = tab_merge(@Structdef.f@, @Program.1.f@, 1);
+           @i @Program.1.f@ = tab_merge(@Program.0.f@, @Structdef.f@, 1);
          @}
-
        |
-         @{
-               @i @Program.0.f@ = new_tab();
-         @}
        ;
 
 Methoddef:
@@ -80,7 +72,7 @@ Parms:
 
        |
          @{
-           @i @Parms.f@ = new_tab();
+           @i @Parms.f@ = tab_new();
          @}
        ;
 
@@ -92,7 +84,7 @@ FeldID:
 
        |
          @{
-           @i @FeldID.f@ = new_tab();
+           @i @FeldID.f@ = tab_new();
          @}
        ;
 
@@ -116,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@,)
          @}