package table; import java.util.HashMap; import function.LispFunction; import function.builtin.*; import function.builtin.cons.*; import function.builtin.math.*; import function.builtin.predicate.*; import function.builtin.special.*; public class FunctionTable { private static FunctionTable uniqueInstance = new FunctionTable(); public static LispFunction lookupFunction(String functionName) { return uniqueInstance.functionTable.get(functionName); } public static boolean isAlreadyDefined(String functionName) { return uniqueInstance.functionTable.containsKey(functionName); } public static void defineFunction(String functionName, LispFunction function) { uniqueInstance.functionTable.put(functionName, function); } public static void reset() { uniqueInstance.initializeFunctionTable(); } private HashMap functionTable; private FunctionTable() { initializeFunctionTable(); } private void initializeFunctionTable() { functionTable = new HashMap<>(); functionTable.put("*", new MULTIPLY()); functionTable.put("+", new PLUS()); functionTable.put("-", new MINUS()); functionTable.put("/", new DIVIDE()); functionTable.put("<", new LESSP()); functionTable.put("=", new EQUALSP()); functionTable.put(">", new GREATERP()); functionTable.put("AND", new AND()); functionTable.put("APPLY", new APPLY()); functionTable.put("ATOM", new ATOM()); functionTable.put("CAR", new FIRST()); functionTable.put("CDR", new REST()); functionTable.put("COND", new COND()); functionTable.put("CONS", new CONS()); functionTable.put("DEFINE-MACRO", new DEFINE_MACRO()); functionTable.put("DEFUN", new DEFUN()); functionTable.put("EQ", new EQ()); functionTable.put("EQUAL", new EQUAL()); functionTable.put("EVAL", new EVAL()); functionTable.put("EXIT", new EXIT()); functionTable.put("FIRST", new FIRST()); functionTable.put("FUNCALL", new FUNCALL()); functionTable.put("GREATERP", new GREATERP()); functionTable.put("IF", new IF()); functionTable.put("LAMBDA", new LAMBDA()); functionTable.put("LENGTH", new LENGTH()); functionTable.put("LET", new LET()); functionTable.put("LIST", new LIST()); functionTable.put("LISTP", new LISTP()); functionTable.put("LOAD", new LOAD()); functionTable.put("NULL", new NULL()); functionTable.put("OR", new OR()); functionTable.put("PRINT", new PRINT()); functionTable.put("QUOTE", new QUOTE()); functionTable.put("REST", new REST()); functionTable.put("SET", new SET()); functionTable.put("SETF", new SETF()); functionTable.put("SETQ", new SETF()); functionTable.put("SYMBOL-FUNCTION", new SYMBOL_FUNCTION()); } }