Created
June 8, 2017 19:36
-
-
Save anonymous/aade6369b57aae99a14f390e042a20bf to your computer and use it in GitHub Desktop.
nil?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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