Functions for Fourth Assignment
Dave Matuszek, Spring 2003

If you have not completed the third assignment (Implementing Lisp, Part I) successfully, then you are in trouble for the fourth assignment (Implementing Lisp, Part II). The following should be of assistance.

The hardest methods to write for Part I are public String toString() and public static Sexpr parse(String arg). I am providing a class, LispUtil, with (almost) these methods in it.

There are two basic ways to use these methods:

Using a .class file:

A .class file is a compiled .java file. Just drop it into the folder with your other .java and .class files and start using it. You don't need the source code. I'm not giving out source code until the final deadline for Part I.

This should work fine with BlueJ. If it doesn't, try this: Delete BlueJ's .pkg, pkh, and .ctxt files from your folder, leaving only the .java and .class files. Then use BlueJ's Open Non BlueJ... command. Something similar should work with any other IDE you are using.

public static Sexpr parse(String input)

Given an input string, parses it and returns it as an S-expression. Dotted pairs are handled correctly.




Sexpr mySexpr = LispUtil.parse("(a . (b c))");

public static String toString(Sexpr sexpr)

Given an S-expression, returns a printable representation of that S-expression. Dotted pairs are handled correctly.

Despite the name, this method does not and cannot override toString() (because it's in my class, not your Sexpr class), so it must be called like an ordinary method; it is not implicitly called when you give a Sexpr as an argument to System.out.println(...) or when you concatenate a Sexpr with a String.




String myString = LispUtil.toString(mySexpr);