From: NeilBrown Date: Mon, 19 Feb 2018 05:46:04 +0000 (+1100) Subject: oceani: Expression etc should be 'exec', not 'binode'. X-Git-Tag: StoneyCreek~5 X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=b0828672cd5eb5c88778ffce7a2135a9d3889229 oceani: Expression etc should be 'exec', not 'binode'. 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 --- diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index bef5b3e..c38fce5 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -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; }$