summaryrefslogtreecommitdiff
path: root/src/displayapp/screens/Calculator.cpp
diff options
context:
space:
mode:
authorMichele Bini <michele.bini@gmail.com>2022-06-11 02:29:19 (GMT)
committerMichele Bini <michele.bini@gmail.com>2022-06-11 02:29:19 (GMT)
commitdeca6736caf2883fadb39c481d44ede4db5e5563 (patch)
tree4c2600609555dac5c6a69309b209b70784eca539 /src/displayapp/screens/Calculator.cpp
parentd5f13f7bd9b567d2e934c549d7096f74b6e06031 (diff)
add back missing error handling; run operators.pop after potentially branching out to see if it results in smaller firmware size
Diffstat (limited to 'src/displayapp/screens/Calculator.cpp')
-rw-r--r--src/displayapp/screens/Calculator.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/displayapp/screens/Calculator.cpp b/src/displayapp/screens/Calculator.cpp
index e1f36f6..e05aedd 100644
--- a/src/displayapp/screens/Calculator.cpp
+++ b/src/displayapp/screens/Calculator.cpp
@@ -204,7 +204,8 @@ bool Calculator::Eval() {
// or (the operator at the top of the operator stack has equal precedence and the token is left associative))
|| (getPrecedence(operators.top()) == getPrecedence(next) && leftAssociative(next)))) {
// need two elements on the output stack to add a binary operator
- if (!output.pushOperator(operators.pop())) return false;
+ if (!output.pushOperator(operators.top())) return false;
+ operators.pop();
}
operators.push(next);
expectingNumber = true;
@@ -229,7 +230,8 @@ bool Calculator::Eval() {
case ')':
while (operators.top() != '(') {
// need two elements on the output stack to add a binary operator
- if (!output.pushOperator(operators.pop())) return false;
+ if (!output.pushOperator(operators.top())) return false;
+ operators.pop();
if (operators.empty()) return false;
}
// discard the left parentheses
@@ -237,7 +239,8 @@ bool Calculator::Eval() {
}
}
while (!operators.empty()) {
- output.pushOperator(operators.pop());
+ if (!output.pushOperator(operators.top())) return false;
+ operators.pop();
}
// perform the calculation
// assert(output.size() == 1);