public void Visit(AdditionalExpression ae) { sb.Append("("); ae.Left.Accept(this); sb.Append("+"); ae.Right.Accept(this); sb.Append(")"); }
public void Visit(AdditionalExpression 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 AdditionalExpression( new DoubleExpression(3), new AdditionalExpression( new DoubleExpression(4), new DoubleExpression(7))); var ep = new ExpressionPrinter(); ep.Visit(e); WriteLine(ep); var calc = new ExpressionCalculator(); calc.Visit(e); WriteLine($"{ep} = {calc.Result}"); ReadKey(); }