43 lines
1.1 KiB
Java
43 lines
1.1 KiB
Java
|
package serene.simple;
|
||
|
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
import serene.simple.builtin.AFn;
|
||
|
import serene.simple.builtin.PrintlnFn;
|
||
|
|
||
|
public class RootScope extends BaseScope {
|
||
|
private final BaseScope parent;
|
||
|
private final HashMap<String, Object> symbolsMapping = new HashMap<String, Object>() {{
|
||
|
put("println", new PrintlnFn());
|
||
|
}};
|
||
|
// "+", PlusFn,
|
||
|
// "-", MinusFn,
|
||
|
// "*", TimesFn,
|
||
|
// "/", ObelusFn,
|
||
|
// "mod", ModFn,
|
||
|
// "now", NowFn,
|
||
|
|
||
|
|
||
|
public RootScope() {
|
||
|
this.parent = null;
|
||
|
System.out.println(this.symbolsMapping.get("println"));
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Object lookupSymbol(String symbolName) {
|
||
|
if (this.symbolsMapping.containsKey(symbolName)) {
|
||
|
return this.symbolsMapping.get(symbolName);
|
||
|
}
|
||
|
else {
|
||
|
throw new RuntimeException(String.format("Variable '%s' is not defined in this scope.",
|
||
|
symbolName));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void insertSymbol(String symbolName, Object symbolValue) {
|
||
|
this.symbolsMapping.put(symbolName, symbolValue);
|
||
|
}
|
||
|
}
|