diff options
Diffstat (limited to 'src/displayapp/screens/Calculator.cpp')
| -rw-r--r-- | src/displayapp/screens/Calculator.cpp | 9 |
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); |
