public void Visit(AdditionExpression4 ae) { sb.Append("("); ae.Left.Accept(this); sb.Append("+"); ae.Right.Accept(this); sb.Append(")"); }
public void Visit(AdditionExpression4 ae) { ae.Left.Accept(this); var a = Result; ae.Right.Accept(this); var b = Result; Result = a + b; }
public void Print(AdditionExpression4 ae, StringBuilder sb) { sb.Append("("); Print((dynamic)ae.Left, sb); sb.Append("+"); Print((dynamic)ae.Right, sb); sb.Append(")"); // dynamic cast -- find correct overload method // slow // runtime binary exception }
public void Run() { Expression4 e = new AdditionExpression4( new DoubleExpression4(4), new AdditionExpression4( new DoubleExpression4(5), new DoubleExpression4(6) ) ); var sb = new StringBuilder(); var ep = new ExpressionPrinter4a(); //ep.Visit(e); ep.Print((dynamic)e, sb); Console.WriteLine(sb); //var cal = new ExpressionCalculator(); //cal.Visit(e); //Console.WriteLine($"{ep} = {cal.Result}"); }