Пример #1
0
 public void Visit(BinaryDiv node)
 {
     sb.Append("(");
     node.LeftChild.Accept(this);
     sb.Append("/");
     node.RightChild.Accept(this);
     sb.Append(")");
 }
Пример #2
0
 public bool TryParse(string formula, out FormulaNode node)
 {
     if (formula == "/")
     {
         node = new BinaryDiv(leftNode, rightNode);
         return(true);
     }
     else
     {
         node = null;
         return(false);
     }
 }
Пример #3
0
        public void Visit(BinaryDiv 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);
                }
            }
        }
Пример #4
0
        public void Visit(BinaryDiv node)
        {
            OperationPriorities priority = prevPriorities.Pop();

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