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

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

            Result = a + b;
        }
예제 #3
0
        static void Main(string[] args)
        {
            var e = new AdditionExpression(
                new DoubleExpression(1),
                new AdditionExpression(
                    new DoubleExpression(2),
                    new DoubleExpression(3)
                    ));

            var ep = new ExpressionPrinter();

            ep.Visit(e);
            Console.WriteLine(ep);

            var calc = new ExpressionCalculator();

            calc.Visit(e);
            Console.WriteLine($"{ep} = {calc.Result}");
        }