2016-12-07 16:38:26 -05:00
|
|
|
/*
|
|
|
|
* Name: Mike Cifelli
|
|
|
|
* Course: CIS 443 - Programming Languages
|
|
|
|
* Assignment: Lisp Interpreter 2
|
|
|
|
*/
|
|
|
|
|
|
|
|
package eval;
|
|
|
|
|
|
|
|
import parser.*;
|
2016-12-14 13:09:41 -05:00
|
|
|
import sexpression.Cons;
|
|
|
|
import sexpression.SExpression;
|
|
|
|
import sexpression.Symbol;
|
2016-12-07 16:38:26 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* <code>PRINT</code> represents the PRINT function in Lisp.
|
|
|
|
*/
|
|
|
|
public class PRINT extends LispFunction {
|
|
|
|
|
|
|
|
// The number of arguments that PRINT takes.
|
|
|
|
private static final int NUM_ARGS = 1;
|
|
|
|
|
|
|
|
public SExpression call(Cons argList) {
|
|
|
|
// retrieve the number of arguments passed to PRINT
|
|
|
|
int argListLength = LENGTH.getLength(argList);
|
|
|
|
|
|
|
|
// make sure we have received the proper number of arguments
|
|
|
|
if (argListLength != NUM_ARGS) {
|
|
|
|
Cons originalSExpr = new Cons(new Symbol("PRINT"), argList);
|
|
|
|
String errMsg = "too " +
|
|
|
|
((argListLength > NUM_ARGS) ? "many" : "few") +
|
|
|
|
" arguments given to PRINT: " + originalSExpr;
|
|
|
|
|
|
|
|
throw new RuntimeException(errMsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
SExpression arg = argList.getCar();
|
|
|
|
|
|
|
|
System.out.println(arg);
|
|
|
|
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|