]> mj.ucw.cz Git - umpf.git/blobdiff - cond.y
fix many little bugs, release 0.1
[umpf.git] / cond.y
diff --git a/cond.y b/cond.y
index 4c1d3d221d188a976ff7fd96d5b42e3e8c07a714..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,12 +74,6 @@ command:      ';' { $$ = tree_malloc(ST_EMPTY); }
                | arrow ';' { $$ = $1; }
                
        
-;
-
-next:  /* empty */ {$$ = tree_malloc(ST_EMPTY); }
-       | command
-       
-
 ;
 
 cif:   KW_IF cond command KW_ELSE command      { 
@@ -234,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;   
+                       }
 ;
 
 %%
@@ -273,5 +279,7 @@ get_var_type(char* var)
 void
 yyerror (char const *s)
 {
-       fprintf (stderr, "Line %d: %s\n", line, s);
+       fprintf (stderr, "Line %d: %s\n Saving your e-mail to default mailbox %s\n", 
+               line, s, default_mailbox);
+       longjmp(env, 1);
 }