public string Visit(MultiplyOpNode visited) { var sb = new StringBuilder(); // parentheses might be needed around children with lower priorities int thisPriority = visited.Accept(priorityGetter); int sonPriority = visited.LeftSon.Accept(priorityGetter); if (sonPriority < thisPriority) { sb.Append("("); } sb.Append(visited.LeftSon.Accept(this)); if (sonPriority < thisPriority) { sb.Append(")"); } sb.Append("*"); sonPriority = visited.RightSon.Accept(priorityGetter); // * is associative - no need for parentheses when RightSon has same priority if (sonPriority < thisPriority) { sb.Append("("); } sb.Append(visited.RightSon.Accept(this)); if (sonPriority < thisPriority) { sb.Append(")"); } return(sb.ToString()); }
public double Visit(MultiplyOpNode caller) { double left = caller.LeftSon.Accept(this); double right = caller.RightSon.Accept(this); return(left * right); }
public int Visit(MultiplyOpNode caller) { int left = caller.LeftSon.Accept(this); int right = caller.RightSon.Accept(this); return(checked (left * right)); }
public string Visit(MultiplyOpNode visited) { var sb = new StringBuilder(); sb.Append("("); sb.Append(visited.LeftSon.Accept(this)); sb.Append("*"); sb.Append(visited.RightSon.Accept(this)); sb.Append(")"); return(sb.ToString()); }
public int Visit(MultiplyOpNode visited) { return(5); }