fix: Unary operators in math evaluator not working correctly
This commit is contained in:
parent
5a4f31bfa5
commit
50a1956d92
@ -144,6 +144,9 @@ namespace hex {
|
|||||||
auto [op, width] = toOperator(pos);
|
auto [op, width] = toOperator(pos);
|
||||||
|
|
||||||
if (op != Operator::Invalid) {
|
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 = { } });
|
inputQueue.push(Token { .type = TokenType::Operator, .op = op, .name = "", .arguments = { } });
|
||||||
pos += width;
|
pos += width;
|
||||||
} else {
|
} else {
|
||||||
@ -239,14 +242,7 @@ namespace hex {
|
|||||||
else if (front.type == TokenType::Operator) {
|
else if (front.type == TokenType::Operator) {
|
||||||
T rightOperand, leftOperand;
|
T rightOperand, leftOperand;
|
||||||
if (evaluationStack.size() < 2) {
|
if (evaluationStack.size() < 2) {
|
||||||
if ((front.op == Operator::Addition || front.op == Operator::Subtraction || front.op == Operator::Not || front.op == Operator::BitwiseNot) && evaluationStack.size() == 1) {
|
this->setError("Not enough operands for operator!");
|
||||||
rightOperand = evaluationStack.top();
|
|
||||||
evaluationStack.pop();
|
|
||||||
leftOperand = 0;
|
|
||||||
} else {
|
|
||||||
this->setError("Not enough operands for operator!");
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
rightOperand = evaluationStack.top();
|
rightOperand = evaluationStack.top();
|
||||||
evaluationStack.pop();
|
evaluationStack.pop();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user