CS342 Expression Evaluator

CS342 Expression Evaluator

Spring 2005

Due Date: Thursday Feb 3, 2005

In this project you will build a very simple arithmetic expression evaluator without using any canned software from the net; that is, you may only use the basic Java IO library to read characters and the Integer.parseInt() method.

I am testing not only your basic ability to write software in Java, but your ability to precisely follow instructions--a crucial skill for a developer. Your code must exactly process input and generate output according to this specification.

Functionality

Your program will accept input from "standard in" System.in and print to "standard out" System.out the correct value indicated by the expression on a line by itself. For example, for input 3+4, your program should print 7 on a line by itself.

You must handle expressions of arbitrary length with multi-digit integers as basic expression atoms and with operators plus and multiply. More formally, here is the grammar you must recognize:

expression
    :    multExpression ( "+" multExpression )*
    ;
multExpression
    :    atom ( "*" atom )*
    ;
atom:    INTEGER
    ;

Don't forget to handle the operator precedence properly; i.e., 3+4*5 is 23 not 35 due to the higher precedence of the multiply operator.

You must ignore whitespace characters: '\t', ' ', and '\n'. Recall that PC's are insane and use "\r\n".

Requirements

You may implement this project any way you want, but you must execute your program by invoking the main method in a class called Eval. You must read from stdin and write to stdout.

Do not put your code in a Java package.

Submission

You must place expr.jar into

/home/submit/cs342/userid

where userid is your username.

The expr.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.

Grading

I will run your project parts via

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

Your grade is an integer from 0..40. 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!