fix unary operator bind order in integral tree parser

This commit is contained in:
Martin Michelsen
2024-05-31 23:05:19 -07:00
parent 64082fa872
commit 5ce4eb8cfc
3 changed files with 17 additions and 15 deletions
+12 -12
View File
@@ -337,18 +337,6 @@ unique_ptr<const IntegralExpression::Node> IntegralExpression::parse_expr(string
throw runtime_error("invalid expression");
}
// Check for unary operators
if (text[0] == '!') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::LOGICAL_NOT,
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '~') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::BITWISE_NOT,
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '-') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::NEGATIVE,
IntegralExpression::parse_expr(text.substr(1)));
}
// Check for binary operators at the root level
using BinType = BinaryOperatorNode::Type;
static const vector<vector<pair<std::string, BinaryOperatorNode::Type>>> binary_operator_levels = {
@@ -392,6 +380,18 @@ unique_ptr<const IntegralExpression::Node> IntegralExpression::parse_expr(string
}
}
// Check for unary operators
if (text[0] == '!') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::LOGICAL_NOT,
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '~') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::BITWISE_NOT,
IntegralExpression::parse_expr(text.substr(1)));
} else if (text[0] == '-') {
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::NEGATIVE,
IntegralExpression::parse_expr(text.substr(1)));
}
// Check for env lookups
if (text.starts_with("F_")) {
char* endptr = nullptr;