Пример #1
0
        private ITripleExpression Atomic()
        {
            GetNext();
            ITripleExpression ret;

            switch (current)
            {
            case State.number:
                ret = new Const(constant);
                GetNext();
                break;

            case State.variable:
                ret = new Variable(Char.ToString(variable));
                GetNext();
                break;

            case State.minus:
                ret = new CheckedSubtract(new Const(0), Atomic());
                break;

            case State.abs:
                ret = new CheckedAbs(Atomic());
                break;

            case State.sqrt:
                ret = new Square(Atomic());
                break;

            case State.lparen:
                ret = AddSubt();
                if (current != State.rparen)
                {
                    Console.WriteLine(") missing");
                    throw new InvalidOperationException(") missing");
                }
                GetNext();
                break;

            default:
                ret = null;
                Console.WriteLine("Unrecognizable format");
                throw new InvalidOperationException("Unrecognizable format");
                break;
            }
            return(ret);
        }
Пример #2
0
        private ITripleExpression AddSubt()
        {
            ITripleExpression left = MulDiv();

            while (true)
            {
                switch (current)
                {
                case State.minus:
                    left = new CheckedSubtract(left, MulDiv());
                    break;

                case State.plus:
                    left = new CheckedAdd(left, MulDiv());
                    break;

                default:
                    return(left);
                }
            }
        }