Closed keon-dev closed 1 week ago
Each token type will have up to two parsing functions associated with is, depending on whether the token is found in a prefix or an infix position.
type (
prefixParseFn func() ast.Expression
infixParseFn func(ast.Expression) ast.Expression .
)
Both functions return an ast.Expression
, but infixParseFn
takes another ast.Expression
which is the left side of the operator being parsed.
Expressions in monkey
-5
!true
!false
5 + 5
5 - 5
5 / 5
5 * 5
foo == bar
foo != bar
foo < bar
foo > bar
5 * (5 + 5)
((5 + 5) * 5) * 5
add(2, 3)
add(add(2, 3), add(5, 10))
max(5, add(5, (5 * 5)))
foo * bar / foobar
add(foo, bar)
let add = fn(x, y) { return x + y; };
fn(x, y) { return x + y }(5, 5)
(fn (x) { return x }(5) + 10) * 10
let result = if (10 > 5) { true } else { false }; // => true