From: Anicka Bernathova Date: Wed, 22 Jul 2009 16:50:54 +0000 (+0200) Subject: add unary minus, fix blocks X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=ee85b211dc8842a86e70a95f48d8a4a3e0a46bf6;p=umpf.git add unary minus, fix blocks --- diff --git a/cond.y b/cond.y index e1390f8..3b5d623 100644 --- a/cond.y +++ b/cond.y @@ -18,7 +18,6 @@ static enum var_type get_var_type(char* var); struct tree* tr; } -%right '!' %token CONST %token NUM %token VAR @@ -36,9 +35,11 @@ static enum var_type get_var_type(char* var); %left '|' %left '^' %left '&' +%right '!' +%left NEG +%type input_init %type input %type command -%type next %type ass %type ass_right %type ass_right_p @@ -51,17 +52,18 @@ static enum var_type get_var_type(char* var); %type leaves %% -input: /* empty */ { $$ = input_tree = tree_malloc(ST_EMPTY); } +input_init: input {input_tree = $$} + +; +input: /* empty */ { $$ = tree_malloc(ST_EMPTY); } | command input { $$ = tree_malloc(ST_BLOCK); $$->pt.block.head = $1; $$->pt.block.tail = $2; - - input_tree = $$; } ; command: ';' { $$ = tree_malloc(ST_EMPTY); } - | '{' command next '}' { + | '{' command input '}' { $$ = tree_malloc(ST_BLOCK); $$->pt.block.head = $2; $$->pt.block.tail = $3; @@ -72,13 +74,6 @@ command: ';' { $$ = tree_malloc(ST_EMPTY); } | arrow ';' { $$ = $1; } -; - -next: /* empty */ {$$ = tree_malloc(ST_EMPTY); } - | input - - - ; cif: KW_IF cond command KW_ELSE command { @@ -235,6 +230,16 @@ ass_right: leaves $$->pt.op.left = $1; $$->pt.op.right = $3; } + | '-' ass_right %prec NEG { + $$ = tree_malloc(ST_OP); + $$->pt.op.op = $1; + $$->pt.op.left = tree_malloc(ST_LEAF); + $$->pt.op.left->pt.leaf.type = L_CONST; + $$->pt.op.left->pt.leaf.value = "0"; + $$->pt.op.left->pt.leaf.n = + store_const("0"); + $$->pt.op.right = $2; + } ; %%