public void Visit(MethCall methCall) { Console.Write($"{methCall.TurtleName}.{methCall.MethName}"); Console.Write("("); methCall.Argument?.Accept(this); Console.Write(")"); }
public void Visit(MethCall methCall) { if (Environment.GetItem(methCall.TurtleName) is TurtleItem turle) { // Check for arguments if (methCall.Argument != null) { methCall.Argument.Accept(this); dynamic arg = Environment.PopFromTheStack(); // Color or identifier if (arg is string) { if (!(arg == "Black" || arg == "Red" || arg == "Green" || arg == "Blue")) { arg = Environment.GetItem(arg).Value; } } // Built-in methods with arguments switch (methCall.MethName) { case "Forward": turle.Forward(arg); break; case "Backward": turle.Backward(arg); break; case "Right": turle.Right(arg); break; case "Left": turle.Left(arg); break; case "LineColor": turle.LineColor(arg); break; case "LineThickness": turle.LineThickness(arg); break; default: throw new ExecutorException($"No built-in method called {methCall.MethName} found"); } } else { // Built-in methods with no arguments switch (methCall.MethName) { case "PenUp": turle.PenUp(); break; case "PenDown": turle.PenDown(); break; default: throw new ExecutorException($"No built-in method called {methCall.MethName} found"); } } } else { throw new ExecutorException($"Method with the name: {methCall} can only be applied on Turtle object"); } }