public void Visit(PlusOperator op)
        {
            op.LeftOperand.Accept(this);
            op.RightOperand.Accept(this);

            _stack.Push(_stack.Pop() + _stack.Pop());
        }
 public void Visit(PlusOperator op)
 {
     op.LeftOperand.Accept(this);
     _resultBuilder.Append(" ");
     op.RightOperand.Accept(this);
     _resultBuilder.Append("+");
 }
Пример #3
0
 private void CreateChild(ref AbstractTreeElement node, string expression, ref int curNumber)
 {
     if (curNumber >= expression.Length)
         return;
     while (expression[curNumber] == ' ' || expression[curNumber] == ')')
         ++curNumber;
     if (expression[curNumber] == '(')
     {
         Operator newOpertator;
         switch (expression[curNumber + 1])
         {
             case '+':
                 newOpertator = new PlusOperator();
                 break;
             case '-':
                 newOpertator = new MinusOperator();
                 break;
             case '*':
                 newOpertator = new MultiplicationOperator();
                 break;
             case '/':
                 newOpertator = new DivisionOperator();
                 break;
             default:
                 throw new System.Exception();
         }
         curNumber += 2;
         var newNode = newOpertator.LeftChild;
         CreateChild(ref newNode, expression, ref curNumber);
         newOpertator.LeftChild = newNode;
         if (expression[curNumber] == ')')
         {
             ++curNumber;
         }
         newNode = newOpertator.RightChild;
         CreateChild(ref newNode, expression, ref curNumber);
         newOpertator.RightChild = newNode;
         node = newOpertator;
     }
     else
     {
         Operand newOperand = new Operand();
         newOperand.Element = 0;
         while (expression[curNumber] != ' ')
         {
             if (expression[curNumber] == ')')
                 break;
             newOperand.Element = newOperand.Element * 10 + (expression[curNumber] - '0');
             ++curNumber;
         }
         node = newOperand;
     }
 }
        public void Visit(PlusOperator op)
        {
            List<Type> parenthesisOperators = new List<Type> { typeof(MultiplicationOperator), typeof(DivisionOperator) };
            FormatBinaryOperator(op, ParenthesisNeeded(parenthesisOperators));

        }
 public void Visit(PlusOperator op)
 {
     Visit((BinaryOperator)op);
 }