From db92811da8d13d5d1b78b6e0a985a919165b4c07 Mon Sep 17 00:00:00 2001 From: kako57 <71569154+kako57@users.noreply.github.com> Date: Tue, 21 Feb 2023 19:40:54 -0500 Subject: [PATCH] Added extra rules for operator precedence --- ASTree.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ASTree.cpp b/ASTree.cpp index 7af32d9..217283e 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -2614,8 +2614,18 @@ static int cmp_prec(PycRef parent, PycRef child) return 1; // Always parenthesize not(x) if (child.type() == ASTNode::NODE_BINARY) { PycRef binChild = child.cast(); - if (parent.type() == ASTNode::NODE_BINARY) - return binChild->op() - parent.cast()->op(); + if (parent.type() == ASTNode::NODE_BINARY) { + PycRef binParent = parent.cast(); + if (binParent->right() == child) { + if (binParent->op() == ASTBinary::BIN_SUBTRACT && + binChild->op() == ASTBinary::BIN_ADD) + return 1; + else if (binParent->op() == ASTBinary::BIN_DIVIDE && + binChild->op() == ASTBinary::BIN_MULTIPLY) + return 1; + } + return binChild->op() - binParent->op(); + } else if (parent.type() == ASTNode::NODE_COMPARE) return (binChild->op() == ASTBinary::BIN_LOG_AND || binChild->op() == ASTBinary::BIN_LOG_OR) ? 1 : -1;