JavaCC and JTB
Language: Java 1.4.2 (
documentation,
API,
tutorial).
Tools:
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.
- javac : Suns java compiler.
javac Main.java // to compile Main.java
- 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/
- 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.
- jtbgj : jtb with generics
- javacc : java parser generator.
javacc jtb.out.jj // generates a parser with a specified name
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 source to target code.
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 target 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