commit 6da2a3fec8f5732e85df7e9050c3090c903a1c08
parent 41e22780fa4e08a9c8e6b16c125ecf587d5c9567
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 17 Apr 2021 10:38:42 -0400
hare::parse: binarithm: simplify loops
Diffstat:
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha
@@ -18,7 +18,7 @@ export fn expression(lexer: *lex::lexer) (ast::expr | error) = {
ltok::IF => if_expr(lexer),
ltok::FOR => abort(), // TODO
ltok::BREAK, ltok::CONTINUE, ltok::RETURN => control(lexer),
- ltok::LET, ltok::CONST => abort(), // TODO
+ ltok::LET, ltok::CONST => binding(lexer),
* => abort(), // Invariant
};
};
@@ -37,15 +37,13 @@ fn binarithm(
};
let tok = lex::lex(lexer)?;
- let j = precedence(tok);
- for (j >= i; j = precedence(tok)) {
+ for (let j = precedence(tok); j >= i; j = precedence(tok)) {
const op = binop_for_tok(tok);
let rvalue = cast(lexer, void)?;
tok = lex::lex(lexer)?;
- let k = precedence(tok);
- for (k > j; k = precedence(tok)) {
+ for (let k = precedence(tok); k > j; k = precedence(tok)) {
lex::unlex(lexer, tok);
rvalue = binarithm(lexer, rvalue, k)?;
tok = lex::lex(lexer)?;
@@ -63,6 +61,10 @@ fn binarithm(
return lvalue;
};
+fn binding(lexer: *lex::lexer) (ast::expr | error) = {
+ abort(); // TODO
+};
+
fn builtin(lexer: *lex::lexer) (ast::expr | error) = {
const tok = match (peek(lexer, ltok::ALLOC, ltok::APPEND, ltok::FREE,
ltok::DELETE, ltok::ABORT, ltok::ASSERT, ltok::STATIC,