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

            if ((int)priority > 1 || priority == OperationPriorities.Sub)
            {
                sb.Append("(");
                prevPriorities.Push(OperationPriorities.Add);
                node.LeftChild.Accept(this);
                sb.Append("+");
                prevPriorities.Push(OperationPriorities.Add);
                node.RightChild.Accept(this);
                sb.Append(")");
            }
            else
            {
                prevPriorities.Push(OperationPriorities.Add);
                node.LeftChild.Accept(this);
                sb.Append("+");
                prevPriorities.Push(OperationPriorities.Add);
                node.RightChild.Accept(this);
            }
        }