]> ocean-lang.org Git - ocean/commitdiff
oceani: Expression etc should be 'exec', not 'binode'.
authorNeilBrown <neil@brown.name>
Mon, 19 Feb 2018 05:46:04 +0000 (16:46 +1100)
committerNeilBrown <neil@brown.name>
Mon, 19 Feb 2018 05:48:50 +0000 (16:48 +1100)
As a 'var' and a 'val' are possible expressions,
'binode' isn't correct.  This is obvious when you
consider that I needed to case $1 for a var or var
before assigning it to $0 for Factor -> Value etc.

So change all these to expect the more generic 'struct exec *'.

Without this change, error handling can try to free a var as though it
was a binode, and get into trouble.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani.mdc

index bef5b3e7904a0d44a91ab9593210abf44a3d7ca8..c38fce52f095cc9279c937bc2b272a5d044e6da0 100644 (file)
@@ -1486,28 +1486,31 @@ and `BFact`s.
 
 ####### Grammar
 
-       $*binode
-       Expression -> Expression or BTerm ${
-                       $0 = new(binode);
-                       $0->op = Or;
-                       $0->left = $<1;
-                       $0->right = $<3;
-               }$
+       $*exec
+       Expression -> Expression or BTerm ${ {
+                       struct binode *b = new(binode);
+                       b->op = Or;
+                       b->left = $<1;
+                       b->right = $<3;
+                       $0 = b;
+               } }$
                | BTerm ${ $0 = $<1; }$
 
-       BTerm -> BTerm and BFact ${
-                       $0 = new(binode);
-                       $0->op = And;
-                       $0->left = $<1;
-                       $0->right = $<3;
-               }$
+       BTerm -> BTerm and BFact ${ {
+                       struct binode *b = new(binode);
+                       b->op = And;
+                       b->left = $<1;
+                       b->right = $<3;
+                       $0 = b;
+               } }$
                | BFact ${ $0 = $<1; }$
 
-       BFact -> not BFact ${
-                       $0 = new(binode);
-                       $0->op = Not;
-                       $0->right = $<2;
-                       }$
+       BFact -> not BFact ${ {
+                       struct binode *b = new(binode);
+                       b->op = Not;
+                       b->right = $<2;
+                       $0 = b;
+               } }$
                ## other BFact
 
 ###### print binode cases
@@ -1587,12 +1590,13 @@ expression operator.
        NEql,
 
 ###### other BFact
-       | Expr CMPop Expr ${
-                       $0 = new(binode);
-                       $0->op = $2.op;
-                       $0->left = $<1;
-                       $0->right = $<3;
-               }$
+       | Expr CMPop Expr ${ {
+                       struct binode *b = new(binode);
+                       b->op = $2.op;
+                       b->left = $<1;
+                       b->right = $<3;
+                       $0 = b;
+       } }$
        | Expr ${ $0 = $<1; }$
 
 ###### Grammar
@@ -1697,35 +1701,39 @@ precedence is handled better I might be able to discard this.
 
 ###### Grammar
 
-       $*binode
-       Expr -> Expr Eop Term ${
-                       $0 = new(binode);
-                       $0->op = $2.op;
-                       $0->left = $<1;
-                       $0->right = $<3;
-               }$
+       $*exec
+       Expr -> Expr Eop Term ${ {
+                       struct binode *b = new(binode);
+                       b->op = $2.op;
+                       b->left = $<1;
+                       b->right = $<3;
+                       $0 = b;
+               } }$
                | Term ${ $0 = $<1; }$
 
-       Term -> Term Top Factor ${
-                       $0 = new(binode);
-                       $0->op = $2.op;
-                       $0->left = $<1;
-                       $0->right = $<3;
-               }$
+       Term -> Term Top Factor ${ {
+                       struct binode *b = new(binode);
+                       b->op = $2.op;
+                       b->left = $<1;
+                       b->right = $<3;
+                       $0 = b;
+               } }$
                | Factor ${ $0 = $<1; }$
 
-       Factor -> ( Expression ) ${
-                       $0 = new_pos(binode, $1);
-                       $0->op = Bracket;
-                       $0->right = $<2;
-               }$
-               | Uop Factor ${
-                       $0 = new(binode);
-                       $0->op = $1.op;
-                       $0->right = $<2;
-               }$
-               | Value ${ $0 = (struct binode *)$<1; }$
-               | Variable ${ $0 = (struct binode *)$<1; }$
+       Factor -> ( Expression ) ${ {
+                       struct binode *b = new_pos(binode, $1);
+                       b->op = Bracket;
+                       b->right = $<2;
+                       $0 = b;
+               } }$
+               | Uop Factor ${ {
+                       struct binode *b = new(binode);
+                       b->op = $1.op;
+                       b->right = $<2;
+                       $0 = b;
+               } }$
+               | Value ${ $0 = $<1; }$
+               | Variable ${ $0 = $<1; }$
 
        $eop
        Eop ->    + ${ $0.op = Plus; }$