Emcee Expressions

Problem Description:

Our Emcee language included expressions, as defined in the BNF below:

expression

constant

identifier

expression binary_op expression

unary_op expression

identifier LEFT_PAREN expression_list RIGHT PAREN

identifier LEFT_PAREN RIGHT_PAREN

LEFT PAREN expression RIGHT PAREN

constant

REAL CONST | INT CONST | STRING CONST

binary_op

: :=

PLUS | MINUS | MULT | DIVIDE | CARAT | MOD

unary_op

MINUS

As we prepare to complete our Emcee interpreter, you are to create C++ classes that

implement the portions highlighted above. For binary operators, you need only handle +

-, * and /. Your unary operator should handle -. Constants are always integers. The design

for these classes can be found below.

Declare all your C++ classes in the file "expression.h".

A reminder about expression notation: An infix expression places the operator between

two operands, or in front of a single operand (e.g. 1 + 2, or - 3). A postfix expression always

puts the operator after the operands (e.g. 1 2 +, or 3 u-). To avoid confusion, when printing

a unary - in postfix format, use the notation u- (as shown above and also in the example

below). When printing infix, use parentheses liberally (again, see example below)

To test your classes, run the main program defined below. This program creates the

following expression, evaluates it, and then prints it in infix and postfix formats:

- 3 * (4 + (9 / 3 ) )