]> mj.ucw.cz Git - umpf.git/commitdiff
add unary minus, fix blocks
authorAnicka Bernathova <anicka@anicka.net>
Wed, 22 Jul 2009 16:50:54 +0000 (18:50 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Wed, 22 Jul 2009 16:50:54 +0000 (18:50 +0200)
cond.y

diff --git a/cond.y b/cond.y
index e1390f83d2580e8eeb63cbc897f9137a41e08b74..3b5d6239ba2bb78e439539a18041545b15e16f26 100644 (file)
--- a/cond.y
+++ b/cond.y
@@ -18,7 +18,6 @@ static enum var_type get_var_type(char* var);
        struct tree* tr;        
 }
 
-%right <n> '!'
 %token <str> CONST
 %token <n> NUM
 %token <str> VAR
@@ -36,9 +35,11 @@ static enum var_type get_var_type(char* var);
 %left <n> '|'
 %left <n> '^'
 %left <n> '&'
+%right <n> '!'
+%left <n> NEG
+%type <tr> input_init 
 %type <tr> input 
 %type <tr> command 
-%type <tr> next 
 %type <tr> ass 
 %type <tr> ass_right 
 %type <tr> ass_right_p
@@ -51,17 +52,18 @@ static enum var_type get_var_type(char* var);
 %type <tr> 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;   
+                       }
 ;
 
 %%