public void Visit(AdditionExpression ae)
 {
     sb.Append("(");
     ae.Left.Accept(this);
     sb.Append("+");
     ae.Right.Accept(this);
     sb.Append(")");
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            AdditionExpression ae = new AdditionExpression(
                new DoubleExpression(1),
                new AdditionExpression(
                    new DoubleExpression(2),
                    new DoubleExpression(3)
                    ));

            ExpressionPrinter ep = new ExpressionPrinter();

            ep.Visit(ae);

            Console.WriteLine(ep);

            ExpressionCalculator ec = new ExpressionCalculator();

            ec.Visit(ae);
            Console.WriteLine($"{ep} = {ec.Result}");
        }