transcendental-lisp/parser/Nil.java

105 lines
2.1 KiB
Java

/*
* Name: Mike Cifelli
* Course: CIS 443 - Programming Languages
* Assignment: Lisp Parser
*/
package parser;
/**
* This class represents NIL in the PL-Lisp implementation.
*/
public class Nil extends Cons {
private static Nil uniqueInstance = new Nil();
/**
* Retrieve the single unique instance of NIL.
*
* @return
* the single unique instance of NIL
*/
public static Nil getUniqueInstance() {
return uniqueInstance;
}
// We are using the Singleton pattern, so the constructor for 'Nil' is
// private.
private Nil() {
super(null, null);
// the car and cdr of NIL both refer to NIL
super.setCar(this);
super.setCdr(this);
}
/**
* Test if this S-expression is NULL.
*
* @return
* <code>true</code>
*/
public boolean nullp() {
return true;
}
/**
* Test if this S-expression is an ATOM.
*
* @return
* <code>true</code>
*/
public boolean atomp() {
return true;
}
/**
* Test if this S-expression is a CONS cell.
*
* @return
* <code>false</code>
*/
public boolean consp() {
return false;
}
/**
* Test if this S-expression is a SYMBOL.
*
* @return
* <code>true</code>
*/
public boolean symbolp() {
return true;
}
/**
* Set the car of this CONS cell to the specified value. This method does
* nothing (the car of NIL can not be changed).
*
* @param newCar
* the value to assign to the car of this CONS cell
*/
public void setCar(SExpression newCar) {}
/**
* Set the cdr of this CONS cell to the specified value. This method does
* nothing (the cdr of NIL can not be changed).
*
* @param newCdr
* the value to assign to the cdr of this CONS cell
*/
public void setCdr(SExpression newCdr) {}
/**
* Returns a string representation of NIL.
*
* @return
* a string representation of NIL
*/
public String toString() {
return "NIL";
}
}