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; }
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}"); }