X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=codea%2Fparser.y;h=74fe1f45c551c11f552c8fa83453829907acf621;hb=12be827731009fbe86ecc7711ff7338ee6a80432;hp=5fc5c8e2d5b09d26791a41d393f1f4a2398ef9bd;hpb=0b896148b2f89bc42079c40ea8ce43d73d4a2c36;p=uebersetzerbau-ss10.git diff --git a/codea/parser.y b/codea/parser.y index 5fc5c8e..74fe1f4 100644 --- a/codea/parser.y +++ b/codea/parser.y @@ -5,6 +5,8 @@ #include "symtable.h" #include "chelper.h" #include "tree.h" + + #define MAX(A,B) (A > B ? A : B) %} %start Input @@ -21,17 +23,29 @@ * geht nicht, weil verschachtelte macros deaktiviert sind */ @end -@autoinh s -@autosyn node imm exprcount +/* beschreibung der attribute + * s: + * f: + * gparamges: + * parms: + * node: + * imm: + * exprcount: + * sin: + * sout: + */ +@autoinh s gparamges +@autosyn node imm @attributes { char *name; } IDENT @attributes { long val; } NUM -@attributes { struct symbol *f; int parms; } Parms +@attributes { struct symbol *f; int paramges; int parms; } Parms @attributes { struct symbol *f; } FeldID Structdef Program -@attributes { struct symbol *s; } Methoddef Statseq Exprs -@attributes { struct symbol *s; struct treenode *node; short imm; int exprcount; } Expr Minusterm Term -@attributes { struct symbol *s; struct treenode *node; } Lexpr Multerm Orterm Feld -@attributes { struct symbol *sin; struct symbol *sout; struct treenode *node; } Statement +@attributes { struct symbol *s; } Methoddef +@attributes { struct symbol *s; int gparamges; } Statseq Exprs +@attributes { struct symbol *s; int gparamges; struct treenode *node; short imm; int exprcount; } Expr Minusterm Term Multerm Orterm +@attributes { struct symbol *s; int gparamges; struct treenode *node; } Lexpr Feld +@attributes { struct symbol *sin; int gparamges; struct symbol *sout; struct treenode *node; } Statement @traversal @postorder c @traversal @preorder reg @@ -65,6 +79,7 @@ Methoddef: @{ @i @Parms.parms@ = 1; @i @Statseq.s@ = tab_merge(@Methoddef.s@, @Parms.f@, 0); + @i @Statseq.gparamges@ = @Parms.paramges@; @gen @revorder(1) func_header(@IDENT.name@); @} ; @@ -81,12 +96,14 @@ Parms: IDENT Parms @{ @i @Parms.1.parms@ = @Parms.parms@ + 1; + @i @Parms.0.paramges@ = @Parms.1.paramges@; @i @Parms.0.f@ = tab_add_symbol(@Parms.1.f@, @IDENT.name@, S_PARM, 1, @Parms.parms@); @} | @{ @i @Parms.f@ = tab_new(); + @i @Parms.paramges@ = @Parms.parms@; @} ; @@ -167,8 +184,8 @@ Statement: @{ statinout() xxputsin(@Expr.s@,) - @i @Statement.node@ = new_node(O_RET, @Expr.node@, TREENULL, 0); - @reg @Statement.node@->reg = next_reg((char *)NULL, 0); @Expr.node@->reg = @Statement.node@->reg; + @i @Statement.node@ = new_node(O_RET, @Expr.node@, TREENULL, @Expr.exprcount@+1); fprintf(stderr, "RETURN: %s (gparamges: %i, exprcount: %i, gesamt %i [maximal: 7])\n", @Expr.gparamges@ + @Expr.exprcount@ + 1 > 7 ? "zu hohe tiefe" : "tiefe passt", @Expr.gparamges@, @Expr.exprcount@+1, @Expr.gparamges@+@Expr.exprcount@+1); + @reg @Statement.node@->reg = @Expr.node@->reg = next_reg((char *)NULL, 0, @Expr.gparamges@); @} ; @@ -193,72 +210,88 @@ Expr: Term @{ @reg @Term.node@->reg = @Expr.node@->reg; - @i @Expr.exprcount@ = 1 + @Term.exprcount@; fprintf(stderr, "(Expr)- Term\n"); + @i @Expr.exprcount@ = @Term.exprcount@; fprintf(stderr, "(Expr)- Term\n"); @} | NOT Term @{ @i @Expr.node@ = TREENULL; - @i @Expr.exprcount@ = 1 + @Term.exprcount@; fprintf(stderr, "(Expr)- NOT Term\n"); + @i @Expr.exprcount@ = @Term.exprcount@; fprintf(stderr, "(Expr)- NOT Term\n"); @} | Term Minusterm @{ - @i @Expr.exprcount@ = 1 + @Term.exprcount@ + @Minusterm.exprcount@; fprintf(stderr, "(Expr)- Term Minusterm\n"); - @i @Expr.node@ = new_node(O_SUB, @Minusterm.node@, @Term.node@, @Expr.exprcount@); + @i @Expr.exprcount@ = @Term.exprcount@ + @Minusterm.exprcount@; fprintf(stderr, "(Expr)- Term Minusterm\n"); + @i @Expr.node@ = new_node(O_SUB, @Term.node@, @Minusterm.node@, @Expr.exprcount@); @i @Expr.imm@ = @Term.imm@ && @Minusterm.imm@; @reg { /* TODO */ @Term.node@->reg = @Expr.node@->reg; - @Term.node@->skip = 1; - @Minusterm.node@->reg = next_reg(@Term.node@->reg, @Expr.node@->skip); + @Term.node@->skip = 0; + @Minusterm.node@->reg = next_reg(@Term.node@->reg, @Expr.node@->skip, @Expr.gparamges@); } @} | Term Multerm @{ - @i @Expr.node@ = TREENULL; - @i @Expr.exprcount@ = 1 + @Term.exprcount@; fprintf(stderr, "(Expr)- Term Multerm\n"); + @i @Expr.exprcount@ = @Term.exprcount@ + @Multerm.exprcount@; fprintf(stderr, "(Expr)- Term Multerm\n"); + @i @Expr.node@ = new_node(O_MUL, @Term.node@, @Multerm.node@, @Expr.exprcount@); + @i @Expr.imm@ = @Term.imm@ && @Multerm.imm@; + + @reg { + /* TODO */ + @Term.node@->reg = @Expr.node@->reg; + @Term.node@->skip = 0; + @Multerm.node@->reg = next_reg(@Term.node@->reg, @Expr.node@->skip, @Expr.gparamges@); + } @} | Term Orterm @{ - @i @Expr.node@ = TREENULL; - @i @Expr.exprcount@ = 1 + @Term.exprcount@; fprintf(stderr, "(Expr)- Term OrTerm\n"); + @i @Expr.exprcount@ = @Term.exprcount@ + @Orterm.exprcount@; fprintf(stderr, "(Expr)- Term Orterm\n"); + @i @Expr.node@ = new_node(O_OR, @Term.node@, @Orterm.node@, @Expr.exprcount@); + @i @Expr.imm@ = @Term.imm@ && @Orterm.imm@; + + @reg { + /* TODO */ + @Term.node@->reg = @Expr.node@->reg; + @Term.node@->skip = 0; + @Orterm.node@->reg = next_reg(@Term.node@->reg, @Expr.node@->skip, @Expr.gparamges@); + } @} | Term '<' Term @{ @i @Expr.node@ = TREENULL; /* das is bloedsinn atm */ @i @Expr.imm@ = @Term.0.imm@ && @Term.1.imm@; - @i @Expr.exprcount@ = 1 + @Term.0.exprcount@ + @Term.1.exprcount@; fprintf(stderr, "(Expr)- Term < Term\n"); + @i @Expr.exprcount@ = @Term.0.exprcount@ + @Term.1.exprcount@; fprintf(stderr, "(Expr)- Term < Term\n"); @} | Term '=' Term @{ @i @Expr.node@ = TREENULL; /* das is bloedsinn atm */ @i @Expr.imm@ = @Term.0.imm@ && @Term.1.imm@; - @i @Expr.exprcount@ = 1 + @Term.0.exprcount@ + @Term.1.exprcount@; fprintf(stderr, "(Expr)- Term = Term\n"); + @i @Expr.exprcount@ = @Term.0.exprcount@ + @Term.1.exprcount@; fprintf(stderr, "(Expr)- Term = Term\n"); @} ; Minusterm: '-' Term Minusterm @{ - @i @Minusterm.0.exprcount@ = 1 + @Term.exprcount@ + @Minusterm.1.exprcount@; fprintf(stderr, "(Minusterm)- - Term Minusterm\n"); + @i @Minusterm.0.exprcount@ = @Term.exprcount@ + @Minusterm.1.exprcount@; fprintf(stderr, "(Minusterm)- - Term Minusterm\n"); @i @Minusterm.node@ = new_node(O_ADD, @Minusterm.1.node@, @Term.node@, @Minusterm.0.exprcount@); @i @Minusterm.imm@ = @Term.imm@ && @Minusterm.1.imm@; @reg { @Minusterm.1.node@->reg = @Minusterm.node@->reg; - @Term.node@->reg = next_reg(@Minusterm.1.node@->reg, @Minusterm.node@->skip); + @Term.node@->reg = next_reg(@Minusterm.1.node@->reg, @Minusterm.node@->skip, @Minusterm.gparamges@); } @} | '-' Term @{ - @i @Minusterm.exprcount@ = 1 + @Term.exprcount@; fprintf(stderr, "(Minusterm)- - Term\n"); + @i @Minusterm.exprcount@ = @Term.exprcount@; fprintf(stderr, "(Minusterm)- - Term\n"); @reg @Term.node@->reg = @Minusterm.node@->reg; @} ; @@ -266,23 +299,39 @@ Minusterm: Multerm: '*' Term Multerm @{ - @i @Multerm.node@ = TREENULL; + @i @Multerm.0.exprcount@ = @Term.exprcount@ + @Multerm.1.exprcount@; fprintf(stderr, "(Multerm)- - Term Multerm\n"); + @i @Multerm.node@ = new_node(O_MUL, @Multerm.1.node@, @Term.node@, @Multerm.0.exprcount@); + @i @Multerm.imm@ = @Term.imm@ && @Multerm.1.imm@; + + @reg { + @Multerm.1.node@->reg = @Multerm.node@->reg; + @Term.node@->reg = next_reg(@Multerm.1.node@->reg, @Multerm.node@->skip, @Multerm.gparamges@); + } @} | '*' Term @{ - @i @Multerm.node@ = TREENULL; + @i @Multerm.exprcount@ = @Term.exprcount@; fprintf(stderr, "(Multerm)- - Term\n"); + @reg @Term.node@->reg = @Multerm.node@->reg; @} ; Orterm: OR Term Orterm @{ - @i @Orterm.node@ = TREENULL; + @i @Orterm.0.exprcount@ = @Term.exprcount@ + @Orterm.1.exprcount@; fprintf(stderr, "(Orterm)- - Term Orterm\n"); + @i @Orterm.node@ = new_node(O_OR, @Orterm.1.node@, @Term.node@, @Orterm.0.exprcount@); + @i @Orterm.imm@ = @Term.imm@ && @Orterm.1.imm@; + + @reg { + @Orterm.1.node@->reg = @Orterm.node@->reg; + @Term.node@->reg = next_reg(@Orterm.1.node@->reg, @Orterm.node@->skip, @Orterm.gparamges@); + } @} | OR Term @{ - @i @Orterm.node@ = TREENULL; + @i @Orterm.exprcount@ = @Term.exprcount@; fprintf(stderr, "(Orterm)- - Term\n"); + @reg @Term.node@->reg = @Orterm.node@->reg; @} ; @@ -291,26 +340,26 @@ Term: '(' Expr ')' @{ @i @Term.node@ = @Expr.node@; - @i @Term.exprcount@ = @Expr.exprcount@ + 1; fprintf(stderr, "(Term)- ( Expr )\n"); + @i @Term.exprcount@ = 1 + @Expr.exprcount@; fprintf(stderr, "(Term)- ( Expr )\n"); @} | NUM @{ - @i @Term.exprcount@ = 1; fprintf(stderr, "(Term)- NUM\n"); + @i @Term.exprcount@ = 0; fprintf(stderr, "(Term)- NUM\n"); @i @Term.node@ = new_number(@NUM.val@, @Term.exprcount@); @i @Term.imm@ = 1; @} | '-' NUM @{ - @i @Term.exprcount@ = 1; fprintf(stderr, "(Term)- - NUM\n"); + @i @Term.exprcount@ = 0; fprintf(stderr, "(Term)- - NUM\n"); @i @Term.node@ = new_number(-1 * (@NUM.val@), @Term.exprcount@); @i @Term.imm@ = 1; @} | THIS @{ - @i @Term.exprcount@ = 1; fprintf(stderr, "(Term)- THIS\n"); + @i @Term.exprcount@ = 0; fprintf(stderr, "(Term)- THIS\n"); @i @Term.node@ = new_param(O_ID, strdup("this"), TREENULL, TREENULL, 0, @Term.exprcount@); @i @Term.imm@ = 0; @} @@ -318,7 +367,7 @@ Term: | IDENT @{ @c check(@Term.s@, @IDENT.name@, S_VAR|S_PARM); - @i @Term.exprcount@ = 1; fprintf(stderr, "(Term)- IDENT\n"); + @i @Term.exprcount@ = 0; fprintf(stderr, "(Term)- IDENT\n"); @i @Term.node@ = new_param(O_ID, @IDENT.name@, TREENULL, TREENULL, tab_lookup(@Term.s@, @IDENT.name@, S_PARM) == SYMNULL ? -1 : tab_lookup(@Term.s@, @IDENT.name@, S_PARM)->param_index, @Term.exprcount@); @i @Term.imm@ = 0; @} @@ -327,27 +376,28 @@ Term: @{ @i @Term.node@ = TREENULL; @i @Term.imm@ = 0; - /*TODO*/@i @Term.exprcount@ = 1; + /*TODO*/@i @Term.exprcount@ = 0; @} | IDENT '(' Exprs ')' @{ @i @Term.node@ = TREENULL; @i @Term.imm@ = 0; - /*TODO*/@i @Term.exprcount@ = 1; + /*TODO*/@i @Term.exprcount@ = 0; @} | Term '.' IDENT '(' Exprs ')' @{ @i @Term.node@ = TREENULL; @i @Term.imm@ = 0; - /*TODO*/@i @Term.exprcount@ = 1; + /*TODO*/@i @Term.exprcount@ = 0; @} ; Exprs: Expr ',' Exprs + /* TODO: exprcount uppen */ | Expr | ;