コード例 #1
0
 private object LookUpVariable(Token name, Expr expr)
 {
     if (locals.TryGetValue(expr, out int distance))
     {
         return(environment.GetAt(distance, name.lexeme));
     }
     else
     {
         return(globals.Get(name));
     }
 }
コード例 #2
0
        public object Get(Token name)
        {
            if (values.TryGetValue(name.lexeme, out object value))
            {
                return(value);
            }

            if (enclosing != null)
            {
                return(enclosing.Get(name));
            }

            throw new RuntimeError(name, $"Undefined variable {name.lexeme}.");
        }