CSCI (Math) 361
Theory of Computation

Software
Fall, 2002


Jones library:

I have written a Java library to support interaction with a datatype equivalent to the set DA in Jones. The files available are:

  • D.Java: An interface for elements of DA. It also includes definitions of constants representing nil, true, and false (and must be written as D.nil, D.dTrue, and D.dFalse).

  • Atom.java: A class to generate atoms of DA.

  • Composite.java: A class to generate elements of the form (a.b) of DA.

  • ListTry.java: An application to show how to use the other files. It includes the reverse program given in class, written to use these classes and interface

  • output.txt: The output of the program ListTry.java.
  • The library is of course written in an object-oriented style, but that should be a simple translation for you. I.e., rather than writing cons(a,b), you instead write b.cons(a) to generate an element with a as the head and b as the tail (be sure to get the order right!). The expressions a.hd() and a.tl() generate the head and tail of an element (which is nil if a is an atom). a.eq(b) determines if a and b are equal and returns the encoding, D.dTrue, of true if they are the same, and the encoding, D.dFalse, of false if they are different. Thus eq always returns an element of D. For convenience I also included the method booleq which returns a real (Java) boolean.

    By the way, "nil" is no longer represented by Java's null. That means that there is no problem sending messages to nil. This makes your life much easier in writing programs.

    Download the files, compile them all (use javac *.java in the directory with the files) and run the application TryJava (by typing java TryJava) to see how the application works. Feel free to use this to test out WHILE programs, though be sure only to use assignment, while, if-then-else, and sequencing in your programs. Feel free to extend the library to include support for the list notation introduced in class, as well as the number representations as lists.


    Back to:

  • CS 361 home page
  • Kim Bruce's home page
  • CS Department home page
  • kim@cs.williams.edu