Пример #1
0
        public static void ProgramMain()
        {
            string roman = "五亿七千三百零二万六千四百五十二";
            //分解:((五)亿)((七千)(三百)(零)(二)万)
            //((六千)(四百)(五十)(二))

            Context1  context = new Context1(roman);
            ArrayList tree    = new ArrayList();

            tree.Add(new GeExpression());
            tree.Add(new ShiExpression());
            tree.Add(new BaiExpression());
            tree.Add(new QianExpression());
            tree.Add(new WanExpression());
            tree.Add(new YiExpression());

            foreach (Expression exp in tree)
            {
                exp.Interpreter(context);
            }

            Console.Write(context.Data);

            Console.Read();
        }
Пример #2
0
        public override void Interpreter(Context1 Context1)
        {
            ArrayList tree = new ArrayList();

            tree.Add(new GeExpression());
            tree.Add(new ShiExpression());
            tree.Add(new BaiExpression());
            tree.Add(new QianExpression());

            foreach (string key in table.Keys)
            {
                if (Context1.Statement.EndsWith(GetPostFix()))
                {
                    int temp = Context1.Data;
                    Context1.Data      = 0;
                    Context1.Statement = Context1.Statement.Substring(0, Context1.Statement.Length - this.GetLength());

                    foreach (Expression exp in tree)
                    {
                        exp.Interpreter(Context1);
                    }
                    Context1.Data = temp + Context1.Data * this.Multiplier();
                }
            }
        }
Пример #3
0
        public virtual void Interpreter(Context1 Context1)
        {
            if (Context1.Statement.Length == 0)
            {
                return;
            }

            foreach (string key in table.Keys)
            {
                int value = table[key];

                if (Context1.Statement.EndsWith(key + GetPostFix()))
                {
                    Context1.Data     += value * this.Multiplier();
                    Context1.Statement = Context1.Statement.Substring(0, Context1.Statement.Length - this.GetLength());
                }
                if (Context1.Statement.EndsWith("零"))
                {
                    Context1.Statement = Context1.Statement.Substring(0, Context1.Statement.Length - 1);
                }
            }
        }