Skip to content

Commit

Permalink
Use infix notation in examples/ast.c
Browse files Browse the repository at this point in the history
Suggested by #10.
  • Loading branch information
hirrolot committed Apr 25, 2021
1 parent efd7831 commit 98960a4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ double eval(const Expr *expr) {
}

#define EXPR(expr) ((Expr *)(Expr[]){expr})
#define OP(op, lhs, rhs) op(EXPR(lhs), EXPR(rhs))
#define OP(lhs, op, rhs) op(EXPR(lhs), EXPR(rhs))

int main(void) {
Expr expr = OP(Add, Const(53), OP(Sub, OP(Div, Const(155), Const(5)), Const(113)));
// 53 + ((155 / 5) - 113)
Expr expr = OP(Const(53), Add, OP(OP(Const(155), Div, Const(5)), Sub, Const(113)));

/*
* Output:
Expand Down

0 comments on commit 98960a4

Please sign in to comment.