예제 #1
0
        public object VisitFunctionStmt(Stmt.Function stmt)
        {
            var function = new LoxFunction(stmt, environment, false);

            environment.Define(stmt.name.Lexeme, function);
            return(null);
        }
예제 #2
0
 public Unit VisitFunction(Stmt.Function stmt)
 {
     Declare(stmt.Name);
     Define(stmt.Name);
     ResolveFunction(stmt, FunctionType.Function);
     return(Unit.Default);
 }
예제 #3
0
        object Stmt.IVisitor <object> .VisitFunctionStmt(Stmt.Function stmt)
        {
            LoxFunction function = new LoxFunction(stmt, environment, false);

            environment.Define(stmt.name.lexeme, function);
            return(null);
        }
예제 #4
0
파일: Interpreter.cs 프로젝트: leddt/cslox
        public Void Visit(Stmt.Function stmt)
        {
            var function = new LoxFunction(stmt, environment, false);

            environment.Define(stmt.Name.Lexeme, function);

            return(Void.Instance);
        }
예제 #5
0
        object Stmt.IVisitor <object> .VisitFunctionStmt(Stmt.Function stmt)
        {
            Declare(stmt.name);
            Define(stmt.name);

            ResolveFunction(stmt, FunctionType.FUNCTION);
            return(null);
        }
예제 #6
0
        public Unit VisitFunction(Stmt.Function stmt)
        {
            // Capture the environment at declaration time.
            string name     = string.Format("<fun {0}>", stmt.Name.Lexeme);
            var    function = new LoxFunction(name, _environment, stmt.Parameters, stmt.Body);

            _environment.Define(stmt.Name.Lexeme, function);
            return(Unit.Default);
        }
예제 #7
0
파일: Resolver.cs 프로젝트: leddt/cslox
        public Void Visit(Stmt.Function stmt)
        {
            Declare(stmt.Name);
            Define(stmt.Name);

            ResolveFunction(stmt, FunctionType.Function);

            return(Void.Instance);
        }
예제 #8
0
        void ResolveFunction(Stmt.Function function, FunctionType type)
        {
            var enclosingFunction = currentFunction;

            currentFunction = type;
            BeginScope();
            function.parameters.ForEach(e =>
            {
                Declare(e);
                Define(e);
            });

            Resolve(function.Body);
            EndScope();
            currentFunction = enclosingFunction;
        }
예제 #9
0
        private void ResolveFunction(Stmt.Function function, FunctionType type)
        {
            FunctionType enclosingFunction = currentFunction;

            currentFunction = type;

            BeginScope();
            foreach (Token p in function.parameters)
            {
                Declare(p);
                Define(p);
            }
            Resolve(function.body);
            EndScope();

            currentFunction = enclosingFunction;
        }
예제 #10
0
        public string VisitFunction(Stmt.Function stmt)
        {
            var builder = new StringBuilder();

            builder.Append("(fun (");
            builder.Append(stmt.Name.Lexeme);
            foreach (var param in stmt.Parameters)
            {
                builder.Append(" ");
                builder.Append(param.Lexeme);
            }

            builder.Append(")");
            foreach (var s in stmt.Body)
            {
                builder.Append(s.Accept(this));
            }
            return(builder.ToString());
        }
예제 #11
0
파일: Resolver.cs 프로젝트: leddt/cslox
        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;
        }
예제 #12
0
 public LoxFunction(Stmt.Function declaration, Environment closure, bool isInitializer)
 {
     this.isInitializer = isInitializer;
     this.closure       = closure;
     this.declaration   = declaration;
 }
예제 #13
0
 private void ResolveFunction(Stmt.Function stmt, FunctionType type)
 {
     ResolveFunction(type, stmt.Parameters, stmt.Body);
 }
예제 #14
0
 public LoxFunction(Stmt.Function declaration, Environment closure, bool isInitializer)
 {
     _declaration   = declaration;
     _closure       = closure;
     _isInitializer = isInitializer;
 }