/// <summary>
        /// Determine whether parentheses are needed around the right subtree base on the current operator.
        /// </summary>
        /// <param name="currentOperator">The current binary node's operator.</param>
        /// <param name="rightSubtree">The right binary subtree.</param>
        /// <returns>True if need parentheses, false if not.</returns>
        private static bool NeedParenthesesRight(BinaryOperator currentOperator, BinaryOperatorQueryToken rightSubtree)
        {
            BinaryOperator rightOperator = BinaryOperator.GetOperator(rightSubtree.OperatorKind);
            if (currentOperator.Precedence < rightOperator.Precedence)
            {
                return false;
            }

            if (currentOperator.Precedence > rightOperator.Precedence)
            {
                return true;
            }

            // They are equal in precedence, 
            return currentOperator.NeedParenEvenWhenTheSame;
        }
 /// <summary>
 /// Determine whether parentheses are needed around the left subtree base on the current operator.
 /// </summary>
 /// <param name="currentOperator">The current binary node's operator.</param>
 /// <param name="leftSubtree">The left binary subtree.</param>
 /// <returns>True if need parenthese, false if not.</returns>
 private static bool NeedParenthesesLeft(BinaryOperator currentOperator, BinaryOperatorQueryToken leftSubtree)
 {
     BinaryOperator leftOperator = BinaryOperator.GetOperator(leftSubtree.OperatorKind);
     return leftOperator.Precedence < currentOperator.Precedence;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Determine whether parentheses are needed around the left subtree base on the current operator.
        /// </summary>
        /// <param name="currentOperator">The current binary node's operator.</param>
        /// <param name="leftSubtree">The left binary subtree.</param>
        /// <returns>True if need parenthese, false if not.</returns>
        private static bool NeedParenthesesLeft(BinaryOperator currentOperator, BinaryOperatorToken leftSubtree)
        {
            BinaryOperator leftOperator = BinaryOperator.GetOperator(leftSubtree.OperatorKind);

            return(leftOperator.Precedence < currentOperator.Precedence);
        }