public void Visit(AdditionExpression ae)
 {
     sb.Append("(");
     ae.Left.Accept(this);
     sb.Append("+");
     ae.Right.Accept(this);
     sb.Append(")");
 }
        public void Visit(AdditionExpression ae)
        {
            ae.Left.Accept(this);
            var a = Result;

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

            Result = a + b;
        }
        public void ClassTest()
        {
            var e = new AdditionExpression(
                new DoubleExpression(1),
                new AdditionExpression(
                    new DoubleExpression(2),
                    new DoubleExpression(3)
                    )
                );
            //var sb = new StringBuilder();
            var ep = new ExpressionPrinter();

            ep.Visit(e);
            Assert.AreEqual("(1+(2+3))", ep.ToString());

            var calc = new ExpressionCalculator();

            calc.Visit(e);
            Assert.AreEqual(6, calc.Result);
        }
        static void main()
        {
            var e = new AdditionExpression(
                new DoubleExpression(1),
                new AdditionExpression(
                    new DoubleExpression(2),
                    new DoubleExpression(3)
                    )
                );
            //var sb = new StringBuilder();
            var ep = new ExpressionPrinter();

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

            var calc = new ExpressionCalculator();

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