SOFTWARE

Language: Java 1.4.2 ( documentation, API, tutorial).

Tools: Detecting software plagiarism. How to write unmaintainable code.

The software is all installed on the SEAS machines just add /u/cs/class/cs132/cbin to your path. You can use the following commands on your SEAS accounts.
  1. javac : Suns java compiler.
          javac Main.java // to compile Main.java 
  2. gjc : generic java compiler.
          gjc Main.java // to compile Main.java 
    For more info about generic java look at http://www.cis.unisa.edu.au/~pizza/gj/

  3. jtb : Java Tree Builder.
          jtb grammar.jj // builds syntaxtree, visitors and jtb.out.jj 
    jtb will build the syntaxtree for the grammar and visitors that traverse the syntax tree nodes. Also it will generate a file called jtb.out.jj. This is the file you need to feed into javacc.

  4. jtbgj : jtb with generics

  5. javacc : java parser generator.
          javacc jtb.out.jj // generates a parser with a specified name 
  6. pgi : Piglet interpreter.
     pgi Factorial.pg // run Factorial.pg 
  7. spgi : Spiglet interpreter.
     spgi Factorial.spg // run Factorial.spg 
  8. kgi : Kanga interpreter.
     kgi Factorial.kgi // run Factorial.kgi 
  9. spim : MIPS emulator.
     spim -file Factorial.s // run Factorial.s 

Quick How-to for JTB/GJ

jtbgj minijava.jj     // generates jtb.out.jj

javacc jtb.out.jj     // generates a parser with a specified name

//now code the visitors to compile java to piglet.

gjc Main.java         // Main.java contains a call of the parser, and visitors
                      // you need to download this file or create your own in your 
                      // working directory. (You might get some warnings about 
                      // unchecked calls which you can ignore.)

java Main < prog.java > prog.pg // builds a syntax tree for prog.java, and  executes 
                                // the visitors, output a piglet program

pgi prog.pg           // run the piglet program. We want the output to be identical
                      // to the output of running the corresponding java program.
Sample Main.java

Setting up software on your own computer

If you want to use your own computer you can follow these instructions,
[NOTE: we will not be able to help you with the installation of any of this
software. If you can't follow these instructions you will have to work from
your SEAS accounts.]

1) Java VM and compiler:
        Get J2SE 1.4.2 from sun. Follow the 
        instructions on SUN's website to install.

2) Java Parser Generator (JavaCC) :
        Get JavaCC from here. Follow the 
        instructions on their website to install.

  Now for those who _DON'T_ want to use generics:

4) Java Tree Builder (JTB):
        Download jtb from http://www.cs.purdue.edu/jtb/download.html.
        Follow instructions on webpage to install. 

  For those who want to use generics:
    
4.1) Download gjc.jar and rtetro.jar.  Copy it to some directory 
     on your computer which I will refer to as LIB_DIR.

4.2) Lets call the directory where you installed J2SE above as J2SE_DIR. 
     Now to run the generic java compiler on Main.java you need to execute
     
     java -classpath .:LIB_DIR/gjc.jar gjc.Main -bootclasspath LIB_DIR/rtretro.jar:J2SE_DIR/java/jre/lib/rt.jar Main.java

     If you are using windows you will need to use \ instead of / for 
     directories to keep Microsoft happy.. 
    
     You will need to use this command often so I suggest making a 
     script or batch file for it.
 
4.3) Now download jtbgj.jar. To run jtbgj on grammar.jj execute 
     the following command:
     
     java -classpath .:jtbgj.jar  EDU.purdue.jtb.JTB 
          
5) Download and install spim from http://www.cs.wisc.edu/~larus/spim.html.

6.1) Download the piglet interpreter pgi.jar. To run the piglet interpreter use:

    java -classpath pgi.jar PgInterpreter < your_file.pg 
    
6.2) Do the same for kanga interpreter kgi.jar.

6.3) The Spiglet intrerpreter is same as Piglet but make sure your programs 
parse with the Spiglet parser spp.jar