Exemplo n.º 1
0
 public void Visit(BinaryMul node)
 {
     sb.Append("(");
     node.LeftChild.Accept(this);
     sb.Append("*");
     node.RightChild.Accept(this);
     sb.Append(")");
 }
Exemplo n.º 2
0
 public bool TryParse(string formula, out FormulaNode node)
 {
     if (formula == "*")
     {
         node = new BinaryMul(leftNode, rightNode);
         return(true);
     }
     else
     {
         node = null;
         return(false);
     }
 }
Exemplo n.º 3
0
        public void Visit(BinaryMul node)
        {
            if (!cachedResult.HasValue)
            {
                node.LeftChild.Accept(this);
                node.RightChild.Accept(this);

                int valueTwo = results.Pop();
                int valueOne = results.Pop();

                checked
                {
                    results.Push(valueOne * valueTwo);
                }
            }
        }
Exemplo n.º 4
0
        public void Visit(BinaryMul node)
        {
            OperationPriorities priority = prevPriorities.Pop();

            if ((int)priority > 6 || priority == OperationPriorities.Div)
            {
                sb.Append("(");
                prevPriorities.Push(OperationPriorities.Mul);
                node.LeftChild.Accept(this);
                sb.Append("*");
                prevPriorities.Push(OperationPriorities.Mul);
                node.RightChild.Accept(this);
                sb.Append(")");
            }
            else
            {
                prevPriorities.Push(OperationPriorities.Mul);
                node.LeftChild.Accept(this);
                sb.Append("*");
                prevPriorities.Push(OperationPriorities.Mul);
                node.RightChild.Accept(this);
            }
        }