/* * 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 * true */ public boolean nullp() { return true; } /** * Test if this S-expression is an ATOM. * * @return * true */ public boolean atomp() { return true; } /** * Test if this S-expression is a CONS cell. * * @return * false */ public boolean consp() { return false; } /** * Test if this S-expression is a SYMBOL. * * @return * true */ 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"; } }