From: NeilBrown Date: Sat, 20 Nov 2021 05:37:04 +0000 (+1100) Subject: oceani: change SimpleStatement to be $*exec, not $*binode X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=2c2269f21afd52650025b7255c000d33929ed635 oceani: change SimpleStatement to be $*exec, not $*binode All current SimpleStatements are binode, but future ones may not be. So change to $*exec. Declare a binode '*b' in 'reduce' header so the variable is always available. Signed-off-by: NeilBrown --- diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index ca6f5d7..a4110da 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -3789,6 +3789,12 @@ which does nothing and is represented as a `NULL` pointer in a `Block` list. Other stand-alone statements will follow once the infrastructure is in-place. +As many statements will use binodes, we declare a binode pointer 'b' in +the common header for all reductions to use. + +###### Parser: reduce + struct binode *b; + ###### Binode types Block, @@ -3866,6 +3872,7 @@ is in-place. }$ $TERM pass + $*exec SimpleStatement -> pass ${ $0 = NULL; }$ | ERROR ${ tok_err(c, "Syntax error in statement", &$1); }$ ## SimpleStatement Grammar @@ -3955,22 +3962,22 @@ printed. ###### SimpleStatement Grammar | print ExpressionList ${ - $0 = new(binode); - $0->op = Print; - $0->right = NULL; - $0->left = reorder_bilist($op = Print; + b->right = NULL; + b->left = reorder_bilist($op = Print; - $0->right = reorder_bilist($left = NULL; + $0 = b = new(binode); + b->op = Print; + b->right = reorder_bilist($left = NULL; } }$ | print ${ - $0 = new(binode); - $0->op = Print; - $0->left = NULL; - $0->right = NULL; + $0 = b = new(binode); + b->op = Print; + b->left = NULL; + b->right = NULL; }$ ###### print binode cases @@ -4039,16 +4046,16 @@ it is declared, and error will be raised as the name is created as ###### SimpleStatement Grammar | Variable = Expression ${ - $0 = new(binode); - $0->op = Assign; - $0->left = $<1; - $0->right = $<3; + $0 = b= new(binode); + b->op = Assign; + b->left = $<1; + b->right = $<3; }$ | VariableDecl = Expression ${ - $0 = new(binode); - $0->op = Declare; - $0->left = $<1; - $0->right =$<3; + $0 = b= new(binode); + b->op = Declare; + b->left = $<1; + b->right =$<3; }$ | VariableDecl ${ @@ -4058,10 +4065,10 @@ it is declared, and error will be raised as the name is created as $1, NULL, 0, NULL); free_var($1); } else { - $0 = new(binode); - $0->op = Declare; - $0->left = $<1; - $0->right = NULL; + $0 = b = new(binode); + b->op = Declare; + b->left = $<1; + b->right = NULL; } }$ @@ -4173,11 +4180,11 @@ function which has a return type, and the "condition" code blocks in ###### SimpleStatement Grammar | use Expression ${ - $0 = new_pos(binode, $1); - $0->op = Use; - $0->right = $<2; - if ($0->right->type == Xvar) { - struct var *v = cast(var, $0->right); + $0 = b = new_pos(binode, $1); + b->op = Use; + b->right = $<2; + if (b->right->type == Xvar) { + struct var *v = cast(var, b->right); if (v->var->type == Tnone) { /* Convert this to a label */ struct value *val;