transcendental-lisp/src/table/FunctionTable.java

79 lines
2.7 KiB
Java
Raw Normal View History

2017-01-29 14:33:46 -05:00
package table;
import java.util.HashMap;
2017-01-29 14:33:46 -05:00
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 {
2017-02-06 13:43:27 -05:00
2017-01-29 14:33:46 -05:00
private static FunctionTable uniqueInstance = new FunctionTable();
2017-02-06 13:43:27 -05:00
2017-01-29 14:33:46 -05:00
public static LispFunction lookupFunction(String functionName) {
return uniqueInstance.functionTable.get(functionName);
}
2017-02-06 13:43:27 -05:00
2017-01-29 14:33:46 -05:00
public static boolean isAlreadyDefined(String functionName) {
return uniqueInstance.functionTable.containsKey(functionName);
}
2017-02-06 13:43:27 -05:00
2017-01-29 14:33:46 -05:00
public static void defineFunction(String functionName, LispFunction function) {
uniqueInstance.functionTable.put(functionName, function);
}
2017-02-06 13:43:27 -05:00
public static void reset() {
uniqueInstance.initializeFunctionTable();
}
2017-02-06 13:43:27 -05:00
2017-01-29 14:33:46 -05:00
private HashMap<String, LispFunction> functionTable;
2017-01-29 14:33:46 -05:00
private FunctionTable() {
initializeFunctionTable();
}
2017-01-29 14:33:46 -05:00
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 CAR());
functionTable.put("CDR", new CDR());
functionTable.put("COND", new COND());
functionTable.put("CONS", new CONS());
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 CAR());
functionTable.put("FUNCALL", new FUNCALL());
functionTable.put("GREATERP", new GREATERP());
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 CDR());
functionTable.put("SETF", new SETF());
functionTable.put("SYMBOL-FUNCTION", new SYMBOL_FUNCTION());
}
}