From 50a1956d92a80f28689f36c0d67d0e11d1c73793 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 11 Nov 2023 21:22:11 +0100 Subject: [PATCH] fix: Unary operators in math evaluator not working correctly --- .../source/content/helpers/math_evaluator.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/plugins/builtin/source/content/helpers/math_evaluator.cpp b/plugins/builtin/source/content/helpers/math_evaluator.cpp index ec0e59a73..175601fef 100644 --- a/plugins/builtin/source/content/helpers/math_evaluator.cpp +++ b/plugins/builtin/source/content/helpers/math_evaluator.cpp @@ -144,6 +144,9 @@ namespace hex { auto [op, width] = toOperator(pos); if (op != Operator::Invalid) { + if (inputQueue.empty() || inputQueue.back().type == TokenType::Bracket || inputQueue.back().type == TokenType::Operator) + inputQueue.push(Token { .type = TokenType::Number, .number = 0, .name = "", .arguments = { } }); + inputQueue.push(Token { .type = TokenType::Operator, .op = op, .name = "", .arguments = { } }); pos += width; } else { @@ -239,14 +242,7 @@ namespace hex { else if (front.type == TokenType::Operator) { T rightOperand, leftOperand; if (evaluationStack.size() < 2) { - if ((front.op == Operator::Addition || front.op == Operator::Subtraction || front.op == Operator::Not || front.op == Operator::BitwiseNot) && evaluationStack.size() == 1) { - rightOperand = evaluationStack.top(); - evaluationStack.pop(); - leftOperand = 0; - } else { - this->setError("Not enough operands for operator!"); - return std::nullopt; - } + this->setError("Not enough operands for operator!"); } else { rightOperand = evaluationStack.top(); evaluationStack.pop();