コード例 #1
0
        public static void Test()
        {
            Context context = new Context();

            context.SetValue("x", 2);
            context.SetValue("y", 5);
            context.SetValue("z", 7);

            IExpression expression = new SubtractExpression(
                new AddExpression(
                    new NumberExpression("x"),
                    new NumberExpression("z")),
                new NumberExpression("y")
                );

            Console.WriteLine($"{context.GetValue("x")} + {context.GetValue("z")} - {context.GetValue("y")} = {expression.Interpret(context)}");
        }
コード例 #2
0
 public override bool Interpret(Context context)
 {
     return(context.GetValue(name));
 }
コード例 #3
0
 public int Interpret(Context context)
 {
     return(context.GetValue(Name));
 }