]> ocean-lang.org Git - ocean/commitdiff
oceani: convert expression parsing to use precedences.
authorNeilBrown <neil@brown.name>
Sun, 9 Jun 2019 23:11:05 +0000 (09:11 +1000)
committerNeilBrown <neil@brown.name>
Sun, 9 Jun 2019 23:11:05 +0000 (09:11 +1000)
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 <neil@brown.name>
csrc/oceani.mdc

index 7f71eccc43fef1deb45106b3456048cc9d574b89..b1b5c334c1bc811c2d0172f45f050125b03d8053 100644 (file)
@@ -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;