示例#1
0
        public void TestInterpreterYearConversion()
        {
            string roman = "MCMXXVIII";
            InterpreterApplicationContext contextImplementation = new InterpreterApplicationContext(roman);

            List <Expression> tree = new List <Expression>
            {
                new ThousandExpression(),
                new HundredExpression(),
                new TenExpression(),
                new OneExpression()
            };

            foreach (Expression exp in tree)
            {
                exp.Interpret(contextImplementation);
            }

            StringAssert.AreEqualIgnoringCase(roman, "MCMXXVIII");
            Assert.AreEqual(contextImplementation.Output, 1928);
        }
示例#2
0
        static void InterpreterTester()
        {
            #region sample 1
            InterpreterContext context = new InterpreterContext();

            ArrayList list = new ArrayList
            {
                new TerminalExpression(),
                new NonterminalExpression(),
                new TerminalExpression(),
                new TerminalExpression()
            };

            foreach (AbstractExpression exp in list)
            {
                exp.Interpret(context);
            }
            #endregion

            #region sample 2
            string roman = "MCMXXVIII";
            InterpreterApplicationContext contextImplementation = new InterpreterApplicationContext(roman);

            List <Expression> tree = new List <Expression>
            {
                new ThousandExpression(),
                new HundredExpression(),
                new TenExpression(),
                new OneExpression()
            };

            foreach (Expression exp in tree)
            {
                exp.Interpret(contextImplementation);
            }

            Console.WriteLine("{0} = {1}",
                              roman, contextImplementation.Output);
            #endregion
        }