Ejemplo n.º 1
0
        public object VisitFunctionStmt(Stmt.Function stmt)
        {
            var function = new LoxFunction(stmt, _environment, false);

            _environment.Define(stmt.Name.Lexeme, function);
            return(null);
        }
Ejemplo n.º 2
0
        public string VisitFunctionStmt(Stmt.Function stmt)
        {
            var builder = new StringBuilder();

            builder.Append("(fun " + stmt.Name.Lexeme + "(");

            foreach (var param in stmt.Parameters)
            {
                if (param != stmt.Parameters[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());
        }
Ejemplo n.º 3
0
        public object VisitFunctionStmt(Stmt.Function stmt)
        {
            Declare(stmt.Name);
            Define(stmt.Name);

            ResolveFunction(stmt, FunctionType.FUNCTION);
            return(null);
        }
Ejemplo n.º 4
0
        private void ResolveFunction(Stmt.Function function, FunctionType type)
        {
            var enclosingFunction = _currentFunction;

            _currentFunction = type;

            BeginScope();
            foreach (var param in function.Parameters)
            {
                Declare(param);
                Define(param);
            }
            Resolve(function.Body);
            EndScope();

            _currentFunction = enclosingFunction;
        }
Ejemplo n.º 5
0
 public LoxFunction(Stmt.Function declaration, EnvironmentScope closure, bool isInitializer)
 {
     _declaration   = declaration;
     _closure       = closure;
     _isInitializer = isInitializer;
 }