diff --git a/src/eval/LambdaExpression.java b/src/eval/LambdaExpression.java deleted file mode 100644 index e7cc669..0000000 --- a/src/eval/LambdaExpression.java +++ /dev/null @@ -1,63 +0,0 @@ -package eval; - -import sexpression.Cons; -import sexpression.SExpression; - -/** - * This class represents a Lisp FUNCTION in the PL-Lisp implementation. - */ -public class LambdaExpression extends SExpression { - - private Cons lexpr; - private UserDefinedFunction function; - - /** - * Create a new FUNCTION with the specified lambda expression and internal representation. - * - * @param lexpr - * the lambda expression of this FUNCTION - * @param function - * the internal representation of this FUNCTION - */ - public LambdaExpression(Cons lexpr, UserDefinedFunction function) { - this.lexpr = lexpr; - this.function = function; - } - - /** - * Test if this S-expression is a FUNCTION. - * - * @return true - */ - public boolean functionp() { - return true; - } - - /** - * Retrieve the lambda expression of this FUNCTION. - * - * @return the lambda expression of this FUNCTION - */ - public Cons getLExpression() { - return lexpr; - } - - /** - * Retrieve the internal representation of this FUNCTION. - * - * @return the user-defined function of this FUNCTION - */ - public UserDefinedFunction getFunction() { - return function; - } - - /** - * Returns a string representation of this FUNCTION. - * - * @return a string representation of this FUNCTION - */ - public String toString() { - return lexpr.toString(); - } - -} diff --git a/src/eval/LispFunction.java b/src/eval/LispFunction.java deleted file mode 100644 index 2513e5c..0000000 --- a/src/eval/LispFunction.java +++ /dev/null @@ -1,33 +0,0 @@ -package eval; - -import sexpression.Cons; -import sexpression.SExpression; - -/** - * A LispFunction is an internal representation of a built-in function in the Lisp - * programming language. - */ -public abstract class LispFunction { - - /** - * Call this Lisp function with the given list of arguments. - * - * @param argList - * the list of arguments to pass to this function (MUST BE A PROPER LIST) - * @return the resulting S-expression of calling this function with the specified arguments - * @throws RuntimeException - * Indicates that an incorrect number of arguments has been passed to this function - * or that one of the arguments is not of the expected type. - */ - public abstract SExpression call(Cons argList); - - /** - * Determine if the arguments passed to this Lisp function should be evaluated. A subclass - * should override this method to return false if it does not want its arguments to be evaluated - * prior to being passed. - */ - public boolean evaluateArguments() { - return true; - } - -} diff --git a/src/eval/SymbolTable.java b/src/eval/SymbolTable.java deleted file mode 100644 index 65966ee..0000000 --- a/src/eval/SymbolTable.java +++ /dev/null @@ -1,79 +0,0 @@ -package eval; - -import java.util.HashMap; - -import sexpression.SExpression; - -/** - * A SymbolTable maps symbol names to values. - */ -public class SymbolTable { - - private HashMap table; - private SymbolTable parent; - - /** - * Create a new symbol table with no parent. - */ - public SymbolTable() { - this(null); - } - - /** - * Create a new symbol table with the specified parent. - * - * @param parent - * the parent of this symbol table - */ - public SymbolTable(SymbolTable parent) { - this.table = new HashMap(); - this.parent = parent; - } - - /** - * Determine if the specified symbol name is in this symbol table. - * - * @param symbolName - * the name of the symbol to look up - * @return true if the symbol is in this symbol table; false otherwise - */ - public boolean contains(String symbolName) { - return table.containsKey(symbolName); - } - - /** - * Returns the value to which the specified symbol name is mapped in this symbol table. - * - * @param symbolName - * the name of the symbol whose associated value is to be returned - * @return the value to which this symbol table maps symbolName, or null if no - * mapping exists - */ - public SExpression get(String symbolName) { - return table.get(symbolName); - } - - /** - * Associates the specified symbol name with the specified value in this symbol table. If the - * symbol table previously contained a mapping for this symbol name, the old value has been - * replaced. - * - * @param symbolName - * the name of the symbol with which the specified value is to be associated - * @param value - * the value to be associated with the specified symbol name - */ - public void put(String symbolName, SExpression value) { - table.put(symbolName, value); - } - - /** - * Returns the parent of this symbol table. - * - * @return the parent of this symbol table - */ - public SymbolTable getParent() { - return parent; - } - -} diff --git a/src/eval/argument/ArgumentValidator.java b/src/function/ArgumentValidator.java similarity index 98% rename from src/eval/argument/ArgumentValidator.java rename to src/function/ArgumentValidator.java index 352fbbc..54ec05d 100644 --- a/src/eval/argument/ArgumentValidator.java +++ b/src/function/ArgumentValidator.java @@ -1,9 +1,9 @@ -package eval.argument; +package function; import java.text.MessageFormat; import error.LispException; -import eval.LENGTH; +import function.builtin.LENGTH; import sexpression.*; public class ArgumentValidator { diff --git a/src/function/LispFunction.java b/src/function/LispFunction.java new file mode 100644 index 0000000..b8a057c --- /dev/null +++ b/src/function/LispFunction.java @@ -0,0 +1,18 @@ +package function; + +import sexpression.*; + +public abstract class LispFunction { + + public abstract SExpression call(Cons argList); + + /** + * Determine if the arguments passed to this Lisp function should be evaluated. A subclass + * should override this method to return false if it does not want its arguments to be evaluated + * prior to being passed. + */ + public boolean evaluateArguments() { + return true; + } + +} diff --git a/src/eval/UserDefinedFunction.java b/src/function/UserDefinedFunction.java similarity index 98% rename from src/eval/UserDefinedFunction.java rename to src/function/UserDefinedFunction.java index 4cc5fb4..b7fd6bc 100644 --- a/src/eval/UserDefinedFunction.java +++ b/src/function/UserDefinedFunction.java @@ -1,8 +1,10 @@ -package eval; +package function; import java.util.ArrayList; +import function.builtin.*; import sexpression.*; +import table.SymbolTable; public class UserDefinedFunction extends LispFunction { diff --git a/src/eval/APPLY.java b/src/function/builtin/APPLY.java similarity index 98% rename from src/eval/APPLY.java rename to src/function/builtin/APPLY.java index 941f456..8e148f9 100644 --- a/src/eval/APPLY.java +++ b/src/function/builtin/APPLY.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.*; import sexpression.*; /** diff --git a/src/eval/ATOM.java b/src/function/builtin/ATOM.java similarity index 94% rename from src/eval/ATOM.java rename to src/function/builtin/ATOM.java index 84fcc8c..d8d39c7 100644 --- a/src/eval/ATOM.java +++ b/src/function/builtin/ATOM.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/CAR.java b/src/function/builtin/CAR.java similarity index 95% rename from src/eval/CAR.java rename to src/function/builtin/CAR.java index e2be950..1ff2d78 100644 --- a/src/eval/CAR.java +++ b/src/function/builtin/CAR.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/CDR.java b/src/function/builtin/CDR.java similarity index 95% rename from src/eval/CDR.java rename to src/function/builtin/CDR.java index 0d21a1f..8262646 100644 --- a/src/eval/CDR.java +++ b/src/function/builtin/CDR.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/COND.java b/src/function/builtin/COND.java similarity index 97% rename from src/eval/COND.java rename to src/function/builtin/COND.java index ef25a67..28f5dee 100644 --- a/src/eval/COND.java +++ b/src/function/builtin/COND.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/CONS.java b/src/function/builtin/CONS.java similarity index 95% rename from src/eval/CONS.java rename to src/function/builtin/CONS.java index 48747e6..2913115 100644 --- a/src/eval/CONS.java +++ b/src/function/builtin/CONS.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/DEFUN.java b/src/function/builtin/DEFUN.java similarity index 98% rename from src/eval/DEFUN.java rename to src/function/builtin/DEFUN.java index aeb1bc6..ad167eb 100644 --- a/src/eval/DEFUN.java +++ b/src/function/builtin/DEFUN.java @@ -1,7 +1,8 @@ -package eval; +package function.builtin; import java.util.HashMap; +import function.*; import sexpression.*; /** diff --git a/src/eval/DIVIDE.java b/src/function/builtin/DIVIDE.java similarity index 96% rename from src/eval/DIVIDE.java rename to src/function/builtin/DIVIDE.java index 72c27f3..aaf8b57 100644 --- a/src/eval/DIVIDE.java +++ b/src/function/builtin/DIVIDE.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/EQ.java b/src/function/builtin/EQ.java similarity index 95% rename from src/eval/EQ.java rename to src/function/builtin/EQ.java index 8aff2dc..9d98d3d 100644 --- a/src/eval/EQ.java +++ b/src/function/builtin/EQ.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/EQUAL.java b/src/function/builtin/EQUAL.java similarity index 96% rename from src/eval/EQUAL.java rename to src/function/builtin/EQUAL.java index 2414f5b..2a9ec1b 100644 --- a/src/eval/EQUAL.java +++ b/src/function/builtin/EQUAL.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/EQUALSP.java b/src/function/builtin/EQUALSP.java similarity index 96% rename from src/eval/EQUALSP.java rename to src/function/builtin/EQUALSP.java index 323cd4f..6bdb456 100644 --- a/src/eval/EQUALSP.java +++ b/src/function/builtin/EQUALSP.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/EVAL.java b/src/function/builtin/EVAL.java similarity index 99% rename from src/eval/EVAL.java rename to src/function/builtin/EVAL.java index 18ad8d4..4f01731 100644 --- a/src/eval/EVAL.java +++ b/src/function/builtin/EVAL.java @@ -1,7 +1,8 @@ -package eval; +package function.builtin; import java.util.HashMap; +import function.*; import sexpression.*; /** diff --git a/src/eval/EXIT.java b/src/function/builtin/EXIT.java similarity index 92% rename from src/eval/EXIT.java rename to src/function/builtin/EXIT.java index 775f352..67d4a00 100644 --- a/src/eval/EXIT.java +++ b/src/function/builtin/EXIT.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; public class EXIT extends LispFunction { diff --git a/src/eval/FUNCALL.java b/src/function/builtin/FUNCALL.java similarity index 91% rename from src/eval/FUNCALL.java rename to src/function/builtin/FUNCALL.java index 5e130a2..3a68677 100644 --- a/src/eval/FUNCALL.java +++ b/src/function/builtin/FUNCALL.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/GREATERP.java b/src/function/builtin/GREATERP.java similarity index 96% rename from src/eval/GREATERP.java rename to src/function/builtin/GREATERP.java index 1589785..955f403 100644 --- a/src/eval/GREATERP.java +++ b/src/function/builtin/GREATERP.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/LAMBDA.java b/src/function/builtin/LAMBDA.java similarity index 98% rename from src/eval/LAMBDA.java rename to src/function/builtin/LAMBDA.java index 34d04b0..ac52dee 100644 --- a/src/eval/LAMBDA.java +++ b/src/function/builtin/LAMBDA.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.*; import sexpression.*; /** diff --git a/src/eval/LENGTH.java b/src/function/builtin/LENGTH.java similarity index 96% rename from src/eval/LENGTH.java rename to src/function/builtin/LENGTH.java index 84947e4..353e312 100644 --- a/src/eval/LENGTH.java +++ b/src/function/builtin/LENGTH.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/LESSP.java b/src/function/builtin/LESSP.java similarity index 96% rename from src/eval/LESSP.java rename to src/function/builtin/LESSP.java index 6d20a34..8746c31 100644 --- a/src/eval/LESSP.java +++ b/src/function/builtin/LESSP.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/LET.java b/src/function/builtin/LET.java similarity index 98% rename from src/eval/LET.java rename to src/function/builtin/LET.java index fc35e96..80698cb 100644 --- a/src/eval/LET.java +++ b/src/function/builtin/LET.java @@ -1,6 +1,8 @@ -package eval; +package function.builtin; +import function.*; import sexpression.*; +import table.SymbolTable; /** * LET represents the LET form in Lisp. diff --git a/src/eval/LIST.java b/src/function/builtin/LIST.java similarity index 93% rename from src/eval/LIST.java rename to src/function/builtin/LIST.java index 207927d..0bcf90e 100644 --- a/src/eval/LIST.java +++ b/src/function/builtin/LIST.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/LISTP.java b/src/function/builtin/LISTP.java similarity index 94% rename from src/eval/LISTP.java rename to src/function/builtin/LISTP.java index 9e63d7e..1db2101 100644 --- a/src/eval/LISTP.java +++ b/src/function/builtin/LISTP.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/LOAD.java b/src/function/builtin/LOAD.java similarity index 97% rename from src/eval/LOAD.java rename to src/function/builtin/LOAD.java index 47f6add..b02ebb7 100644 --- a/src/eval/LOAD.java +++ b/src/function/builtin/LOAD.java @@ -1,8 +1,9 @@ -package eval; +package function.builtin; import java.io.FileInputStream; import java.io.FileNotFoundException; +import function.LispFunction; import parser.LispParser; import sexpression.*; diff --git a/src/eval/MINUS.java b/src/function/builtin/MINUS.java similarity index 96% rename from src/eval/MINUS.java rename to src/function/builtin/MINUS.java index decd8eb..cbe15dc 100644 --- a/src/eval/MINUS.java +++ b/src/function/builtin/MINUS.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/MULTIPLY.java b/src/function/builtin/MULTIPLY.java similarity index 92% rename from src/eval/MULTIPLY.java rename to src/function/builtin/MULTIPLY.java index 8472430..c20be32 100644 --- a/src/eval/MULTIPLY.java +++ b/src/function/builtin/MULTIPLY.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/NULL.java b/src/function/builtin/NULL.java similarity index 94% rename from src/eval/NULL.java rename to src/function/builtin/NULL.java index 91c7d6a..19607e7 100644 --- a/src/eval/NULL.java +++ b/src/function/builtin/NULL.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/PLUS.java b/src/function/builtin/PLUS.java similarity index 92% rename from src/eval/PLUS.java rename to src/function/builtin/PLUS.java index 09a58f2..82adc29 100644 --- a/src/eval/PLUS.java +++ b/src/function/builtin/PLUS.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/PRINT.java b/src/function/builtin/PRINT.java similarity index 94% rename from src/eval/PRINT.java rename to src/function/builtin/PRINT.java index d11f653..9401e91 100644 --- a/src/eval/PRINT.java +++ b/src/function/builtin/PRINT.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/QUOTE.java b/src/function/builtin/QUOTE.java similarity index 95% rename from src/eval/QUOTE.java rename to src/function/builtin/QUOTE.java index 33f7faf..fa0aee9 100644 --- a/src/eval/QUOTE.java +++ b/src/function/builtin/QUOTE.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.LispFunction; import sexpression.*; /** diff --git a/src/eval/SETF.java b/src/function/builtin/SETF.java similarity index 97% rename from src/eval/SETF.java rename to src/function/builtin/SETF.java index 711843a..0f25359 100644 --- a/src/eval/SETF.java +++ b/src/function/builtin/SETF.java @@ -1,6 +1,8 @@ -package eval; +package function.builtin; +import function.*; import sexpression.*; +import table.SymbolTable; /** * SETF represents the SETF form in Lisp. diff --git a/src/eval/SYMBOL_FUNCTION.java b/src/function/builtin/SYMBOL_FUNCTION.java similarity index 97% rename from src/eval/SYMBOL_FUNCTION.java rename to src/function/builtin/SYMBOL_FUNCTION.java index f768284..5cd4762 100644 --- a/src/eval/SYMBOL_FUNCTION.java +++ b/src/function/builtin/SYMBOL_FUNCTION.java @@ -1,5 +1,6 @@ -package eval; +package function.builtin; +import function.*; import sexpression.*; /** diff --git a/src/interpreter/LispInterpreter.java b/src/interpreter/LispInterpreter.java index dfe1ae5..da00f73 100644 --- a/src/interpreter/LispInterpreter.java +++ b/src/interpreter/LispInterpreter.java @@ -4,7 +4,7 @@ import java.io.*; import java.text.MessageFormat; import error.*; -import eval.EVAL; +import function.builtin.EVAL; import parser.LispParser; import sexpression.SExpression; diff --git a/src/sexpression/LambdaExpression.java b/src/sexpression/LambdaExpression.java new file mode 100644 index 0000000..8055e46 --- /dev/null +++ b/src/sexpression/LambdaExpression.java @@ -0,0 +1,31 @@ +package sexpression; + +import function.UserDefinedFunction; + +public class LambdaExpression extends SExpression { + + private Cons lambdaExpression; + private UserDefinedFunction function; + + public LambdaExpression(Cons lambdaExpression, UserDefinedFunction function) { + this.lambdaExpression = lambdaExpression; + this.function = function; + } + + public boolean functionp() { + return true; + } + + public Cons getLambdaExpression() { + return lambdaExpression; + } + + public UserDefinedFunction getFunction() { + return function; + } + + public String toString() { + return lambdaExpression.toString(); + } + +} diff --git a/src/table/SymbolTable.java b/src/table/SymbolTable.java new file mode 100644 index 0000000..b33f4f0 --- /dev/null +++ b/src/table/SymbolTable.java @@ -0,0 +1,43 @@ +package table; + +import java.util.HashMap; + +import sexpression.SExpression; + +public class SymbolTable { + + private HashMap table; + private SymbolTable parent; + + /** + * Create a new symbol table with no parent. + */ + public SymbolTable() { + this(null); + } + + /** + * Create a new symbol table with the specified parent. + */ + public SymbolTable(SymbolTable parent) { + this.table = new HashMap(); + this.parent = parent; + } + + public boolean contains(String symbolName) { + return table.containsKey(symbolName); + } + + public SExpression get(String symbolName) { + return table.get(symbolName); + } + + public void put(String symbolName, SExpression value) { + table.put(symbolName, value); + } + + public SymbolTable getParent() { + return parent; + } + +} diff --git a/test/eval/argument/ArgumentValidatorTester.java b/test/function/ArgumentValidatorTester.java similarity index 98% rename from test/eval/argument/ArgumentValidatorTester.java rename to test/function/ArgumentValidatorTester.java index 500d07d..3193644 100644 --- a/test/eval/argument/ArgumentValidatorTester.java +++ b/test/function/ArgumentValidatorTester.java @@ -1,11 +1,11 @@ -package eval.argument; +package function; import static org.junit.Assert.*; import org.junit.*; import error.ErrorManager; -import eval.argument.ArgumentValidator.*; +import function.ArgumentValidator.*; import sexpression.*; public class ArgumentValidatorTester {