CS342 Expression Evaluator

CS342 Expression Evaluator

Spring 2005

Due Date: Thursday Feb 10, 2005

In this project, you will be given another students project to which you must add functionality. Further, you must write up a short report indicating your thoughts on the code you inherited.

Functionality

Your program must now accept nested parenthesized expressions. For example, the following are valid expressions:

3
3+4
3*(4+5)
(4)
((3+4)*5)+3

Improperly nested expressions must be flagged as an error such as:

3)
(3+4
((3+4)

etc...

The output must be the same, a single line with the integer answer.

The new grammar would look like:

expression
    :    multExpression ( "+" multExpression )*
    ;
multExpression
    :    atom ( "*" atom )*
    ;
atom:    INTEGER
    |    '(' expressions ')'
    ;

which should give you a huge clue about how to enhance the code if the other person followed the traditional recursive-descent parsing strategy.

The Report

This report does not have to be heavily structured. I am looking for the following information:

You get the idea. Just generally tell me about the experience.

Submission

You must place expr2.jar into

/home/submit/cs342/userid

where userid is your username.

The expr2.jar jar must contain both Java and .class files for your project.

Do not use a package for your code. The main class must be Eval, as it was before!

As for the written report, please print it out and hand it in beginning of class.

Grading

I will run your project parts via

java -cp /home/submit/cs342/userid/expr2.jar Eval < expression-input.txt

Your grade is an integer from 0..20. You will receive a score of 0 if your program is not executable exactly in this fashion; that is, class name and jar must be exactly right. For you PC folks, note that case is significant for class names and file names on linux!