From e96a9148cef03554ac07203c2e2441277c9b5845 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 10 Jun 2019 09:11:05 +1000 Subject: [PATCH] oceani: convert expression parsing to use precedences. As precedences are now working (and largely have been for a long time). it is time to start using them for oceani. Signed-off-by: NeilBrown --- csrc/oceani.mdc | 52 +++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index 7f71ecc..b1b5c33 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -2472,8 +2472,11 @@ room for ambiguity, so a full conditional expression is allowed in there. ###### Grammar + $LEFT $$ifelse + ## expr precedence + $*exec - Expression -> BoolExpr if Expression else Expression ${ { + Expression -> Expression if Expression else Expression $$ifelse ${ { struct binode *b1 = new(binode); struct binode *b2 = new(binode); b1->op = CondExpr; @@ -2484,7 +2487,7 @@ room for ambiguity, so a full conditional expression is allowed in there. b2->right = $<5; $0 = b1; } }$ - | BoolExpr ${ $0 = $<1; }$ + ## expression grammar ###### print binode cases @@ -2542,48 +2545,48 @@ if the result would make a difference. OrElse, Not, -###### Grammar +###### expr precedence + $LEFT or + $LEFT and + $LEFT not - $*exec - BoolExpr -> BoolExpr or BTerm ${ { +###### expression grammar + | Expression or Expression ${ { struct binode *b = new(binode); b->op = Or; b->left = $<1; b->right = $<3; $0 = b; } }$ - | BoolExpr or else BTerm ${ { + | Expression or else Expression ${ { struct binode *b = new(binode); b->op = OrElse; b->left = $<1; b->right = $<4; $0 = b; } }$ - | BTerm ${ $0 = $<1; }$ - BTerm -> BTerm and BFact ${ { + | Expression and Expression ${ { struct binode *b = new(binode); b->op = And; b->left = $<1; b->right = $<3; $0 = b; } }$ - | BTerm and then BFact ${ { + | Expression and then Expression ${ { struct binode *b = new(binode); b->op = AndThen; b->left = $<1; b->right = $<4; $0 = b; } }$ - | BFact ${ $0 = $<1; }$ - BFact -> not BFact ${ { + | not Expression ${ { struct binode *b = new(binode); b->op = Not; b->right = $<2; $0 = b; } }$ - ## other BFact ###### print binode cases case And: @@ -2691,15 +2694,17 @@ expression operator. Eql, NEql, -###### other BFact - | Expr CMPop Expr ${ { +###### expr precedence + $LEFT CMPop + +###### expression grammar + | Expression CMPop Expression ${ { struct binode *b = new(binode); b->op = $2.op; b->left = $<1; b->right = $<3; $0 = b; } }$ - | Expr ${ $0 = $<1; }$ ###### Grammar @@ -2801,34 +2806,35 @@ precedence is handled better I might be able to discard this. Absolute, Negate, Bracket, -###### Grammar +###### expr precedence + $LEFT Eop + $LEFT Top + $LEFT Uop - $*exec - Expr -> Expr Eop Term ${ { +###### expression grammar + | Expression Eop Expression ${ { struct binode *b = new(binode); b->op = $2.op; b->left = $<1; b->right = $<3; $0 = b; } }$ - | Term ${ $0 = $<1; }$ - Term -> Term Top Factor ${ { + | Expression Top Expression ${ { struct binode *b = new(binode); b->op = $2.op; b->left = $<1; b->right = $<3; $0 = b; } }$ - | Factor ${ $0 = $<1; }$ - Factor -> ( Expression ) ${ { + | ( Expression ) ${ { struct binode *b = new_pos(binode, $1); b->op = Bracket; b->right = $<2; $0 = b; } }$ - | Uop Factor ${ { + | Uop Expression ${ { struct binode *b = new(binode); b->op = $1.op; b->right = $<2; -- 2.43.0