From 7ae9ddaee95f816d324525ed42bd5b6f1e427c9b Mon Sep 17 00:00:00 2001 From: r4 Date: Thu, 23 Dec 2021 16:51:10 +0100 Subject: [PATCH] multi-line expressions --- calculate_pi.script | 6 +++++- parse.c | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/calculate_pi.script b/calculate_pi.script index 1bf4a5e..d489ae8 100644 --- a/calculate_pi.script +++ b/calculate_pi.script @@ -5,7 +5,11 @@ iterations := 100 while k - iterations { k_f := float(k) - sum = sum + 1.0 / pow(16.0, k_f) * (4.0 / (8.0 * k_f + 1.0) - 2.0 / (8.0 * k_f + 4.0) - 1.0 / (8.0 * k_f + 5.0) - 1.0 / (8.0 * k_f + 6.0)) + sum = sum + 1.0 / pow(16.0, k_f) * + (4.0 / (8.0 * k_f + 1.0) - + 2.0 / (8.0 * k_f + 4.0) - + 1.0 / (8.0 * k_f + 5.0) - + 1.0 / (8.0 * k_f + 6.0)) k = k + 1 } diff --git a/parse.c b/parse.c index df7973a..e7ac89f 100644 --- a/parse.c +++ b/parse.c @@ -177,6 +177,14 @@ static ExprRet expr(IRToks *out_ir, TokList *toks, Map *funcs, Scope *parent_sc, negate = true; } + /* Delete newline if we're definitely expecting an operand. */ + if (t->tok.kind == TokOp && t->tok.Op == OpNewLn) { + if (t == start) + start = t->next; + t = t->next; + toklist_del(toks, t->prev, t->prev); + } + /* Collapse parentheses. */ if (t->tok.kind == TokOp && t->tok.Op == OpLParen) { ExprRet r;