transcendental-lisp/eval/QUOTE.java

48 lines
1.2 KiB
Java

/*
* Name: Mike Cifelli
* Course: CIS 443 - Programming Languages
* Assignment: Lisp Interpreter 1
*/
package eval;
import parser.*;
/**
* <code>QUOTE</code> represents the QUOTE form in Lisp.
*/
public class QUOTE extends LispFunction {
// The number of arguments that QUOTE takes.
private static final int NUM_ARGS = 1;
public SExpression call(Cons argList) {
// retrieve the number of arguments passed to QUOTE
int argListLength = LENGTH.getLength(argList);
// make sure we have received exactly one argument
if (argListLength != NUM_ARGS) {
Cons originalSExpr = new Cons(new Symbol("QUOTE"), argList);
String errMsg = "too " +
((argListLength > NUM_ARGS) ? "many" : "few") +
" arguments given to QUOTE: " + originalSExpr;
throw new RuntimeException(errMsg);
}
return argList.getCar();
}
/**
* Determine if the arguments passed to this Lisp function should be
* evaluated.
*
* @return
* <code>false</code>
*/
public boolean evaluateArguments() {
return false;
}
}