CMPS 144 Fall 2008
Programming Assignment #5: Evaluating Fully-Parenthesized Arithmetic Expressions
Due: 6pm, November 4

Provided to you is a collection of Java interfaces and classes that form a software system to evalute (a limited form of) fully-parenthesized arithmetic expressions, or FPAE's. All the relevant .java files are here. (Tokenizer.java is not accessible to you; rather, you should download Tokenizer_x.java but change its name to Tokenizer.java.) (FPAEEvaluator is the application, i.e., the class in which the main() method exists).

As it stands, this software system is capable of evaluating FPAE's comprised of parentheses (i.e., ( and )), integer literals (e.g., 317, 2), and the binary operators +, -, *, and / (for addition, subtraction, multiplication, and division, respectively).

Here are some examples of such FPAE's:

Your job is to augment the collection of interfaces and classes so that the a broader class of FPAE's can be evaluated by the system.

Specifically, we want to include the exponentiation operator, ^ (where a^b denotes a raised to the b-th power) and the relational operators ==, <, >, , and , which have the traditional interpretations.

The convention we shall use (which is similar to that used in the C programming language) is that an expression involving a relational operator will evaluate to 1 if it is true and to 0 if it is false. Hence, the expression (32 < 5), for example, will evaluate to 0, whereas 3 == 3 will evaluate to 1.

We also want to allow the use of variables, or identifiers, in FPAE's, and the assignment operator, =, for the purpose of assigning values to them. Identifiers will consist of the lowercase letter x followed by an integer in the range 0 to 99, as in x3 or x67. (Note that x3 and x03 are one and the same.) By default, an identifier's value is zero. The value of an expression involving an assignment is that of its second operand. For example, the expression (x3 = 5) evaluates to 5 and, in addition, has the side effect of changing the value of x3 to 5, so that any subsequent use of x3 will evaluate to 5 (absent any intervening assignment to x3, of course).

As an example of using identifiers and assignment, consider the FPAE

(x0 = ((3 + (x1 = 4)) * x1))

This expression evaluates to 28 and has the side effects of making the values associated to x0 and x1 28 and 4, respectively. Hence, if the next FPAE to be evaluated were

(x1 = (x0 - x1))

the result would be 28 - 4, or 24, and, as a side effect, the value of x1 would be changed to 24. The intent, then, is for identifiers to retain their values (or to have them changed, via assignment) as evaluation continues from one FPAE to another.