###### 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;
b2->right = $<5;
$0 = b1;
} }$
- | BoolExpr ${ $0 = $<1; }$
+ ## expression grammar
###### print binode cases
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:
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
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;