From ecbc58fb917c292f05bed401afe7be0a80971d80 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Wed, 23 Sep 2015 17:53:39 +0200 Subject: different operators can have the same precedence now * SciTECO now has the same operator precedence table as C. * It is numerically important whether different operators have the same precedence. E.g. "5*2/4" used to be evaluated by SciTECO as "5*(2/4)" since division had a higher precedence than multiplication. Within in real (!) numbers this would be the expected evaluation order. Users of other programming languages however would expect the expression to be evaluated as "(5*2)/4" which makes a numerical difference when working with integers. * Operator precedence has been implemented by encoding it into the enumeration values used to represent different operators. Calculating the precedence of a given operator can then be done very efficiently and elegantly (in our case using a plain right shift operation). * documentation updated. We use a precedence table now. --- src/expressions.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/expressions.cpp') diff --git a/src/expressions.cpp b/src/expressions.cpp index 8d21388..6b1e8fe 100644 --- a/src/expressions.cpp +++ b/src/expressions.cpp @@ -93,7 +93,8 @@ Expressions::push_calc(Expressions::Operator op) gint first = first_op(); /* calculate if op has lower precedence than op on stack */ - if (first >= 0 && operators.peek(first) <= op) + if (first >= 0 && + precedence(operators.peek(first)) <= precedence(op)) calc(); return push(op); -- cgit v1.2.3