public override void Execute(Context context)
 {
     foreach (MelodyExpression melodyExpression in m_Children)
         {
             melodyExpression.Execute(context);
         }
         SelfExecute(context);
 }
Exemplo n.º 2
0
        public void Test()
        {
            string str = "10 + 2 - 5 + 4 + 9";
            Context context = new Context(str);

            AbstractExpression expression = new NonterminalExpression();

            int result = expression.Interpret(context);
            Assert.AreEqual(30, result);
        }
Exemplo n.º 3
0
        public static void Test()
        {
            var expressionList = new List<AbstractExpression>
            {
                new TerminalExpressionA(),
                new TerminalExpressionB()
            };

            var context = new Context();

            expressionList.ForEach(e => e.Interpret(context));
        }
        public override int Interpret(Context context)
        {
            int result = 0;
            string token;

            while ((token = context.GetToken()) != null) {
                int val;
                if (int.TryParse(token, out val)) {
                    // 数字
                    result += val;
                } else {
                    // その他
                }
            }

            return result;
        }
Exemplo n.º 5
0
 public abstract int Interpret(Context context);
 protected abstract void SelfExecute(Context context);
Exemplo n.º 7
0
 protected override void SelfExecute(Context context)
 {
 }