- java.lang.Object
-
- org.mal_lang.lib.Scope<T>
-
public class Scope<T> extends Object
Scope stores maps on a stack. Each map is a 'scope' of values uniquely identified by their map keys. Values from previous scopes may be retrieved with the lookup() and lookdown() methods.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(String key, T value)
Adds a value to the current scope (map).Scope<T>
getScopeFor(String key)
Map<String,T>
getSymbols()
T
look(String key)
Looks only at the current scope and returns the value associated with the key.T
lookdown(String key)
Iterates the scope from the top down (front to back), and returns the value of the first map containing the key.T
lookup(String key)
Iterates the scopes from the bottom up (back to front), and returns the value of the first map containing the key.String
toString()
-
-
-
Method Detail
-
lookup
public T lookup(String key)
Iterates the scopes from the bottom up (back to front), and returns the value of the first map containing the key.- Parameters:
key
- Object key- Returns:
- Object associated with the first match of key, or null if not found
-
lookdown
public T lookdown(String key)
Iterates the scope from the top down (front to back), and returns the value of the first map containing the key.- Parameters:
key
- Object key- Returns:
- Object associated with the first match of key, or null if not found
-
look
public T look(String key)
Looks only at the current scope and returns the value associated with the key.- Parameters:
key
- Object key- Returns:
- Object associated with the match of key, or null if not found
-
add
public void add(String key, T value)
Adds a value to the current scope (map).- Parameters:
key
- Key associated with objectvalue
- Value associated with the key
-
-