public override void Execute(Context context)
 {
     foreach (MelodyExpression melodyExpression in m_Children)
         {
             melodyExpression.Execute(context);
         }
         SelfExecute(context);
 }
        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);
        }
Beispiel #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;
        }
 public abstract int Interpret(Context context);
 protected abstract void SelfExecute(Context context);
 protected override void SelfExecute(Context context)
 {
 }