From 5597bc72671d0128e6f0dba446c4dc8d47bf37d0 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 25 Nov 2024 18:58:53 +0300 Subject: fixed subtle operator precedence bug * It was possible to provoke operator right-associativity when placing a high-precedence operator between two low-precedence operators. 1-6*5-1 evaluated to -28 instead of the expected -30. * The reason is that SciTECO relies on operators to be resolved from left-to-right as soon as possible. The higher precedence operator prevents that and pushing the 2nd "-" only evaluated 6*5. At the end 1-30-1 would be left on the stack. teco_expressions_eval() however evaluates from right-to-left which is wrong in this case. * Instead, we now do a full eval on every operator with a lower precedence, making sure that 1-30 is evaluated first. --- tests/testsuite.at | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/testsuite.at') diff --git a/tests/testsuite.at b/tests/testsuite.at index 59b1041..74df3a0 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -52,6 +52,12 @@ AT_SETUP([Missing left operand]) AT_CHECK([$SCITECO -e '+23='], 1, ignore, ignore) AT_CLEANUP +AT_SETUP([Operator precedence]) +AT_CHECK([$SCITECO -e "(1-6*5)+29\"N(0/0)'"], 0, ignore, ignore) +AT_CHECK([$SCITECO -e "(1-6*5-1)+30\"N(0/0)'"], 0, ignore, ignore) +AT_CHECK([$SCITECO -e "(1-6*5-1*2)+31\"N(0/0)'"], 0, ignore, ignore) +AT_CLEANUP + AT_SETUP([Closing loops at the correct macro level]) AT_CHECK([$SCITECO -e '@^Ua{>}