Skip to content

Instantly share code, notes, and snippets.

Created June 8, 2017 19:36
Show Gist options
  • Save anonymous/aade6369b57aae99a14f390e042a20bf to your computer and use it in GitHub Desktop.
Save anonymous/aade6369b57aae99a14f390e042a20bf to your computer and use it in GitHub Desktop.
nil?
module Lox
class Environment
def initialize(enclosing : Environment | Nil)
@enclosing = enclosing
@values = {} of String => Type
end
def initialize()
initialize(nil)
end
def get(name : Token)
value = @values.fetch(name.lexeme, nil)
unless value.nil?
return value
end
unless @enclosing.nil?
return @enclosing.as(Environment).get(name)
end
raise RuntimeError.new(name, "Undefined variable '" + name.lexeme + "'.")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment