]> mj.ucw.cz Git - umpf.git/blobdiff - cond.y
unify BUFSIZE
[umpf.git] / cond.y
diff --git a/cond.y b/cond.y
index 4816a03635660129b2a6873b19a8d5ca5e7a4e7c..f46afe528f7b6869f7521ac0f10d1e5375677761 100644 (file)
--- a/cond.y
+++ b/cond.y
@@ -3,8 +3,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#include "lex.h"
-#include "cond.h"
+#include "umpf.h"
 
 static struct tree* tree_malloc(int type);
 
@@ -20,6 +19,7 @@ static struct tree* tree_malloc(int type);
 %token <str> CONST
 %token <n> NUM
 %token <str> VAR
+%token <str> KW_DISCARD
 %token <str> KW_PIPE KW_MAIL KW_COPY
 %token '(' ')' '{' '}' ';'
 %nonassoc KW_IF
@@ -48,7 +48,7 @@ static struct tree* tree_malloc(int type);
 %type <tr> leaves 
 
 %%
-input: /* empty */     { $$ = input_tree = NULL; }
+input: /* empty */     { $$ = input_tree = tree_malloc(ST_EMPTY); }
        | command input {       $$ = tree_malloc(ST_BLOCK); 
                                $$->pt.block.head = $1;
                                $$->pt.block.tail = $2;
@@ -71,7 +71,7 @@ command:       ';' { $$ = tree_malloc(ST_EMPTY); }
        
 ;
 
-next:  /* empty */ {$$ = NULL; }
+next:  /* empty */ {$$ = tree_malloc(ST_EMPTY); }
        | command
        
 
@@ -87,36 +87,37 @@ cif:        KW_IF cond command KW_ELSE command      {
                                        $$ = tree_malloc(ST_IF);
                                        $$->pt.tif.c = $2;
                                        $$->pt.tif.i = $3;
-                                       $$->pt.tif.e = NULL;
+                                       $$->pt.tif.e = tree_malloc(ST_EMPTY); 
                                }
 ;
 
 cond:  '!' cond {
                                $$ = tree_malloc(ST_COND);
                                $$->pt.cond.left = $2;  
-                               $$->pt.cond.right = NULL;       
+                               $$->pt.cond.right = NULL; 
                                $$->pt.cond.op = $1;    
-
+                               $$->pt.cond.type = OP_BOOL;     
                }
        | cond '|' cond {
                                $$ = tree_malloc(ST_COND);
                                $$->pt.cond.left = $1;  
                                $$->pt.cond.right = $3; 
                                $$->pt.cond.op = $2;    
-
+                               $$->pt.cond.type = OP_BOOL;     
                        }
        | cond '&' cond {
                                $$ = tree_malloc(ST_COND);
                                $$->pt.cond.left = $1;  
                                $$->pt.cond.right = $3; 
                                $$->pt.cond.op = $2;    
-
+                               $$->pt.cond.type = OP_BOOL;     
                        }
        | cond '^' cond {
                                $$ = tree_malloc(ST_COND);
                                $$->pt.cond.left = $1;  
                                $$->pt.cond.right = $3; 
                                $$->pt.cond.op = $2;    
+                               $$->pt.cond.type = OP_BOOL;     
 
                        }
        | '(' cond ')' { $$ = $2; }
@@ -125,7 +126,13 @@ cond:      '!' cond {
                                                $$->pt.cond.left = $1;  
                                                $$->pt.cond.right = $3; 
                                                $$->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:   '>'
@@ -144,26 +151,23 @@ ass:
 
                                        $$->pt.ass.left = tree_malloc(ST_LEAF);
                                        $$->pt.ass.left->pt.leaf.type = L_VAR;
-                                       $$->pt.ass.left->pt.leaf.value.s = $1;
-
+                                       $$->pt.ass.left->pt.leaf.value = $1;
+                                       $$->pt.ass.left->pt.leaf.n = find_var($1, var_hash);
                                        $$->pt.ass.right = $3;
                                }
 ;
 
-leaves:                NUM     { 
-                               $$ = tree_malloc(ST_LEAF);
-                               $$->pt.leaf.type = L_NUM;
-                               $$->pt.leaf.value.n = $1;
-                       }
-               | VAR   {
+leaves:                VAR     {
                                $$ = tree_malloc(ST_LEAF);
                                $$->pt.leaf.type = L_VAR;
-                               $$->pt.leaf.value.s = $1;
+                               $$->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.s = $1;
+                               $$->pt.leaf.value = $1;
+                               $$->pt.leaf.n = store_const($1);
                        }
 ;
 
@@ -173,14 +177,20 @@ arrow:    left ARROW right ass_right  {
                                        $$->pt.arrow.kw_left = $1;
                                        $$->pt.arrow.kw_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";
+                               }
 ;
 
-left:  /* empty */ {$$=NULL;}
+left:  /* empty */ { $$ = NULL;}
        | KW_COPY { $$ = "copy"; }
 
 ;
 
-right: /* empty */ {$$ = NULL; }
+right: /* empty */ { $$ = NULL; }
        | KW_PIPE { $$ = "pipe"; }
        | KW_MAIL { $$ = "mail"; }
 ;