Example #1
0
        public override Operand Copy()
        {
            NaturalLog copy = new NaturalLog();

            copy.LeftSuccessor = LeftSuccessor.Copy();
            return(copy);
        }
Example #2
0
        public override Operand Simplify()
        {
            NaturalLog simplifiedExpression = new NaturalLog();

            simplifiedExpression.LeftSuccessor = LeftSuccessor.Simplify();
            return(simplifiedExpression);
        }
Example #3
0
        // Method that will create an appropriate operator class
        // from the obtained character.
        private void CreateNode(char operat0r)
        {
            Operand result = null;

            switch (operat0r)
            {
            case '+':
                result = new Addition();
                break;

            case '-':
                result = new Subtraction();
                break;

            case '*':
                result = new Multiplication();
                break;

            case '/':
                result = new Division();
                break;

            case '^':
                result = new Power();
                break;

            // Now for operators that take one argument.
            case '!':
                result = new Factorial();
                break;

            case 'l':
                result = new NaturalLog();
                break;

            case 'e':
                result = new Exp();
                break;

            case 'c':
                result = new Cosine();
                break;

            case 's':
                result = new Sine();
                break;
            }
            if (result is BinaryOperator)
            {
                // Add the operands to the binary operator.
                ((BinaryOperator)result).LeftSuccessor  = operands[operands.Count - 2];
                ((BinaryOperator)result).RightSuccessor = operands[operands.Count - 1];

                // Remove the operands from the stack.
                operands.RemoveAt(operands.Count - 1);
                operands.RemoveAt(operands.Count - 1);
            }
            else
            {
                // Same story, add operand to unary operator.
                ((UnaryOperator)result).LeftSuccessor = operands[operands.Count - 1];

                // Remove operand from stack.
                operands.RemoveAt(operands.Count - 1);
            }

            // Add the sub tree on top of the operands stack.
            operands.Add(result);
        }