X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=cond.y;h=5410156de9db8915290caf5550d866641268f55f;hb=8c49eea02255539aa7c92ec3c1bdd5dc9bc737c5;hp=fd5dc304303c6f8f14d38b52f743dddf15a93536;hpb=951c2b57090768a74a9e788ffedc5a7e10400472;p=umpf.git diff --git a/cond.y b/cond.y index fd5dc30..5410156 100644 --- a/cond.y +++ b/cond.y @@ -3,7 +3,7 @@ #include #include -#include "brum.h" +#include "umpf.h" static struct tree* tree_malloc(int type); @@ -16,35 +16,36 @@ static struct tree* tree_malloc(int type); struct tree* tr; } +%right '!' %token CONST %token NUM %token VAR -%token KW_DISCARD -%token KW_PIPE KW_MAIL KW_COPY +%token KW_DISCARD +%token KW_PIPE KW_MAIL KW_COPY %token '(' ')' '{' '}' ';' %nonassoc KW_IF %nonassoc KW_ELSE %left ARROW %left EQ NEQ GE LE '<' '>' RE NRE -%left '=' -%left '.' -%left '+' '-' -%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 left -%type right +%type left +%type right %type leaves %% @@ -128,6 +129,11 @@ cond: '!' cond { $$->pt.cond.op = $2; $$->pt.cond.type = OP_REL; } + | ass_right { + $$ = tree_malloc(ST_COND); + $$->pt.cond.left = $1; + $$->pt.cond.type = JUST_BOOL; + } ; rop: '>' @@ -141,13 +147,13 @@ rop: '>' ; ass: - VAR '=' ass_right { + VAR '=' ass_right_p { $$ = tree_malloc(ST_ASS); $$->pt.ass.left = tree_malloc(ST_LEAF); $$->pt.ass.left->pt.leaf.type = L_VAR; $$->pt.ass.left->pt.leaf.value = $1; - + $$->pt.ass.left->pt.leaf.n = find_var($1, var_hash); $$->pt.ass.right = $3; } ; @@ -156,42 +162,72 @@ leaves: VAR { $$ = tree_malloc(ST_LEAF); $$->pt.leaf.type = L_VAR; $$->pt.leaf.value = $1; + $$->pt.leaf.n = find_var($1, var_hash); } | CONST { $$ = tree_malloc(ST_LEAF); $$->pt.leaf.type = L_CONST; $$->pt.leaf.value = $1; + $$->pt.leaf.n = store_const($1); } ; arrow: left ARROW right ass_right { $$ = tree_malloc(ST_ARROW); $$->pt.arrow.s = $4; - $$->pt.arrow.kw_left = $1; - $$->pt.arrow.kw_right = $3; + $$->pt.arrow.left = $1; + $$->pt.arrow.right = $3; } | left ARROW KW_DISCARD { //FIXME: actually left does not make sense here $$ = tree_malloc(ST_ARROW); $$->pt.arrow.s = NULL; - $$->pt.arrow.kw_left = NULL; - $$->pt.arrow.kw_right = "discard"; + $$->pt.arrow.left = K_EMPTY; + $$->pt.arrow.right = K_DISCARD; } ; -left: /* empty */ { $$ = NULL;} - | KW_COPY { $$ = "copy"; } +left: /* empty */ { $$ = K_EMPTY;} + | KW_COPY { $$ = K_COPY; } + +; +right: /* empty */ { $$ = K_EMPTY; } + | KW_PIPE { $$ = K_PIPE; } + | KW_MAIL { $$ = K_MAIL; } ; -right: /* empty */ { $$ = NULL; } - | KW_PIPE { $$ = "pipe"; } - | KW_MAIL { $$ = "mail"; } +ass_right_p: '(' ass_right ')' {$$ = $2; } + | ass_right {$$ = $1; } ; ass_right: leaves | ass_right '.' ass_right { $$ = tree_malloc(ST_OP); - $$->pt.op.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; }