Reminder: Look at <file:/home/jake/CSC/index.html> for updates or corrections!
Goal: This optional exercise will give you practice on a mid-size application.
You’re going to be working with the Java Expression Parser, JEP. JEP is a set of classes that can parse and evaluate arithmetic expressions. You can use it as a desk calculator, or call it from a program. In this exercise, we’re going to be working with and extending our own copy of JEP. We’re imagining that your collaboration has given you a couple of things to do with this code. They want to get the improved versions from CVS when you’re done.
First, create a local copy of the exercise files.
tar xf ~jake/CSC/exercise7.tar
This gives you a CVS repository containing the JEP source code and scripts. To get a working copy, check it out:
cvs checkout jep
There are several scripts available to you. First, build your version:
Then run it, and ask it to evaluate some simple expressions:
JEP - Enter q to quit
JEP > 1+2
JEP > cos(0.)
JEP > q
There are a couple of test classes available in your directory. You can run them directly via:
The source code is in the “src” tree. There is also some limited documentation available in the doc directory.
The “RunLots” class provides a way of invoking the library a number of times. It takes two arguments, e.g.:
java RunLots “1+cos(0)” 20000
will create a parser and evaluate 1+cos(0) in a loop that executes 20000 times. Note that you should use quotes around the expression to avoid problems with Linux trying to interpret the parentheses.
To check the performance of some code, you can acquire profile data with:
./gather RunLots “1+cos(0)” 20000
and then run PerfAnal to look at it with
“gather” takes the class you want to run as a first argument, followed by any arguments that class needs.
Remember, to succeed you have to have working code for both of the tasks at the end of the exercise period.
We start by learning our way around a complex code.
Unfortunately, this version of JEP can’t understand “sin(pi)”:
JEP - Enter q to quit
JEP > sin(pi)
Unrecognized symbol "sin"
Syntax Error (implicit multiplication not enabled)
You’re to add support for sin() and make sure it works.
There are a couple of possible approaches:
1) Consult a note on structure available at file:/home/jake/CSC/jep/Addition.html
2) Generalize from the test case for cosine, TestCosine.java
3) Read the code, perhaps even search the code, trying to figure out what’s going on.
4) Consult the JavaDocs at file:/home/jake/CSC/jep/doc/index.html (JavaDoc is a system for generating documentation from the source code and associated comments)
We’ll be discussing which of these you found most useful.
RunLots is too slow. Please make it a factor of two faster. The comments at the top talk about what it has to do; make sure that your version still does that! Hint: There’s one line in the JEP.java file that takes about 1/3 of the time. But will that be enough?
It will probably require some experimentation to find the change(s) needed to make this program work. We’ll be discussing how you kept track of those, and how you knew when the program was working.