예제 #1
0
        private Expression readExpression()
        {
            Console.WriteLine(" 1: Const Expression\n 2: Var Expression\n 3: Arith Expression");
            int c = Convert.ToInt32(Console.ReadLine());

            if (c == 1)
            {
                Console.WriteLine("Input constant expression");
                ConstExpression cx = new ConstExpression(Convert.ToInt32(Console.ReadLine()));
                return((Expression)cx);
            }
            else if (c == 2)
            {
                Console.WriteLine("Input variable expression");
                VarExpression ve = new VarExpression(Console.ReadLine());
                return((Expression)ve);
            }
            else if (c == 3)
            {
                ArithExpression ae = new ArithExpression();
                Console.WriteLine("Input left expression");
                ae.setL(readExpression());
                Console.WriteLine("Input operator");
                ae.setOp(Console.ReadLine()[0]);
                Console.WriteLine("Input right expression");
                ae.setR(readExpression());
                return((Expression)ae);
            }
            return(null);
        }
예제 #2
0
        void ButtonSubmitArithmeticClick(object sender, EventArgs e)
        {
            String          operand = textBoxArithmeticOperand.Text;
            ArithExpression ae      = new ArithExpression();

            ae.setL(leftExpression);
            ae.setOp(operand[0]);
            ae.setR(rightExpression);
            expression = ae;
            finished();
        }