From 8c49eea02255539aa7c92ec3c1bdd5dc9bc737c5 Mon Sep 17 00:00:00 2001 From: Anicka Bernathova Date: Wed, 15 Jul 2009 23:18:55 +0200 Subject: [PATCH] fix ass_right bugs, finish print_code --- code.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ cond.y | 45 +++++++++++++++++++++++++++++++++------------ 2 files changed, 91 insertions(+), 12 deletions(-) diff --git a/code.c b/code.c index 070f783..2cee897 100644 --- a/code.c +++ b/code.c @@ -114,6 +114,22 @@ evaluate(struct tree* t, int pref_var, struct list* where) return new_3par_instr(OPC_CAT, left, right, pref_var, where); break; + case '+': + return new_3par_instr(OPC_PLUS, left, + right, pref_var, where); + break; + case '-': + return new_3par_instr(OPC_MINUS, left, + right, pref_var, where); + break; + case '*': + return new_3par_instr(OPC_MUL, left, + right, pref_var, where); + break; + case '/': + return new_3par_instr(OPC_DIV, left, + right, pref_var, where); + break; default: die("evaluate: got to default"); } @@ -367,9 +383,51 @@ print_code(void) case OPC_GT: printf("GT %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); break; + case OPC_LT: + printf("LT %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; + case OPC_LE: + printf("LE %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; + case OPC_GE: + printf("GE %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; + case OPC_RE: + printf("RE %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; + case OPC_NRE: + printf("NRE %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; + case OPC_NEQ: + printf("NEQ %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; + case OPC_EQ: + printf("EQ %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; case OPC_AND: printf("AND %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); break; + case OPC_OR: + printf("OR %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; + case OPC_XOR: + printf("XOR %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; + case OPC_PLUS: + printf("PLUS %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; + case OPC_MINUS: + printf("MINUS %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; + case OPC_MUL: + printf("MUL %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; + case OPC_DIV: + printf("DIV %d %d %d\n", p->u.tpop.l, p->u.tpop.r, p->u.tpop.res); + break; + case OPC_NOT: + printf("NOT %d %d\n", p->u.dpop.par, p->u.dpop.res); + break; case OPC_NOP: puts("NOP"); break; diff --git a/cond.y b/cond.y index ec5bc8e..5410156 100644 --- a/cond.y +++ b/cond.y @@ -16,6 +16,7 @@ static struct tree* tree_malloc(int type); struct tree* tr; } +%right '!' %token CONST %token NUM %token VAR @@ -26,24 +27,23 @@ static struct tree* tree_malloc(int type); %nonassoc KW_ELSE %left ARROW %left EQ NEQ GE LE '<' '>' RE NRE -%left '=' +%left '=' %left '.' %left '+' '-' %left '*' '/' %left '|' %left '^' %left '&' -%left '!' %type input %type command %type next %type ass %type ass_right +%type ass_right_p %type cif %type arrow %type cond %type rop -%type bop %type left %type right %type leaves @@ -147,7 +147,7 @@ rop: '>' ; ass: - VAR '=' ass_right { + VAR '=' ass_right_p { $$ = tree_malloc(ST_ASS); $$->pt.ass.left = tree_malloc(ST_LEAF); @@ -196,20 +196,41 @@ right: /* empty */ { $$ = K_EMPTY; } | KW_MAIL { $$ = K_MAIL; } ; +ass_right_p: '(' ass_right ')' {$$ = $2; } + | ass_right {$$ = $1; } +; + ass_right: leaves - | ass_right bop ass_right { + | ass_right '.' ass_right { + $$ = tree_malloc(ST_OP); + $$->pt.op.op = $2; + $$->pt.op.left = $1; + $$->pt.op.right = $3; + } + | ass_right '+' ass_right { + $$ = tree_malloc(ST_OP); + $$->pt.op.op = $2; + $$->pt.op.left = $1; + $$->pt.op.right = $3; + } + | ass_right '-' ass_right { + $$ = tree_malloc(ST_OP); + $$->pt.op.op = $2; + $$->pt.op.left = $1; + $$->pt.op.right = $3; + } + | ass_right '*' ass_right { + $$ = tree_malloc(ST_OP); + $$->pt.op.op = $2; + $$->pt.op.left = $1; + $$->pt.op.right = $3; + } + | ass_right '/' ass_right { $$ = tree_malloc(ST_OP); $$->pt.op.op = $2; $$->pt.op.left = $1; $$->pt.op.right = $3; } -; - -bop: '.' {$$ = $1} - | '+' {$$ = $1} - | '-' {$$ = $1} - | '*' {$$ = $1} - | '/' {$$ = $1} ; %% -- 2.39.2