package serene.simple; import java.util.HashMap; import serene.simple.builtin.PrintlnFn; import serene.simple.builtin.QuitFn; import serene.simple.builtin.PlusFn; public class RootScope extends BaseScope { private final BaseScope parent; private final HashMap symbolsMapping = new HashMap() {{ put("println", new PrintlnFn()); put("quit", new QuitFn()); put("+", new PlusFn()); put("System", System.class); put("Boolean", Boolean.class); put("String", String.class); }}; // "+", 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); } }