public string VisitFunctionStmt(Stmt.FunctionStmt stmt) { var builder = new StringBuilder(); builder.Append($"(fun {stmt.Name.Lexeme}("); foreach (var param in stmt.Params) { if (param != stmt.Params[0]) { builder.Append(" "); } builder.Append(param.Lexeme); } builder.Append(") "); foreach (var body in stmt.Body) { builder.Append(body.Accept(this)); } builder.Append(")"); return(builder.ToString()); }
public object VisitFunctionStmt(Stmt.FunctionStmt stmt) { Declare(stmt.Name); Define(stmt.Name); ResolveFunction(stmt, FunctionType.FUNCTION); return(null); }
private void ResolveFunction(Stmt.FunctionStmt function, FunctionType type) { var enclosingFunction = _currentFunction; _currentFunction = type; BeginScope(); foreach (var param in function.Params) { Declare(param); Define(param); } Resolve(function.Body); EndScope(); _currentFunction = enclosingFunction; }
public LoxFunction(Stmt.FunctionStmt declaration, Environment closure, bool isInitializer) { Declaration = declaration; Closure = closure; IsInitializer = isInitializer; }