Пример #1
0
        public void executeBlock(IList <Stmt> statements, RosellaEnvironment environment)
        {
            var previous = this.environment;

            try
            {
                this.environment = environment;

                foreach (var statement in statements)
                {
                    execute(statement);
                }
            }
            finally
            {
                this.environment = previous;
            }
        }
Пример #2
0
        public object call(Interpreter interpreter, IList <object> arguments)
        {
            var environment = new RosellaEnvironment(closure);

            for (var i = 0; i < [email protected]; i++)
            {
                environment.define(declaration.@params[i].lexeme, arguments[i]);
            }

            try
            {
                interpreter.executeBlock(declaration.body, environment);
            }
            catch (Return returnValue)
            {
                return(returnValue.value);
            }
            return(null);
        }
Пример #3
0
 public Interpreter(Action <RuntimeError> errorFunc)
 {
     this.errorFunc = errorFunc;
     environment    = globals;
     globals.define("clock", new Clock());
 }
Пример #4
0
 public RosellaFunction(Stmt.Function declaration, RosellaEnvironment closure)
 {
     this.declaration = declaration;
     this.closure     = closure;
 }
 public RosellaEnvironment(RosellaEnvironment enclosing = null)
 {
     this.enclosing = enclosing;
 }