예제 #1
0
 public void Visit(AdditionExpression4 ae)
 {
     sb.Append("(");
     ae.Left.Accept(this);
     sb.Append("+");
     ae.Right.Accept(this);
     sb.Append(")");
 }
예제 #2
0
        public void Visit(AdditionExpression4 ae)
        {
            ae.Left.Accept(this);
            var a = Result;

            ae.Right.Accept(this);
            var b = Result;

            Result = a + b;
        }
예제 #3
0
 public void Print(AdditionExpression4 ae, StringBuilder sb)
 {
     sb.Append("(");
     Print((dynamic)ae.Left, sb);
     sb.Append("+");
     Print((dynamic)ae.Right, sb);
     sb.Append(")");
     // dynamic cast -- find correct overload method
     // slow
     // runtime binary exception
 }
예제 #4
0
        public void Run()
        {
            Expression4 e = new AdditionExpression4(
                new DoubleExpression4(4),
                new AdditionExpression4(
                    new DoubleExpression4(5),
                    new DoubleExpression4(6)
                    )
                );

            var sb = new StringBuilder();
            var ep = new ExpressionPrinter4a();

            //ep.Visit(e);
            ep.Print((dynamic)e, sb);
            Console.WriteLine(sb);

            //var cal = new ExpressionCalculator();
            //cal.Visit(e);
            //Console.WriteLine($"{ep} = {cal.Result}");
        }