Your program must be able to read in the following expressions. You may wish to construct a BNF grammar in the style of the cookie exercise as an initial task.
Compile, run, and test your program with at least these expressions:
let x = 1;
(let x = 1) + x;
(let a = 2) + 3 * a - 5;
(let x = (let y = (let z = 1))) + x + y + z;
1 + (let x = 1) + (let y = 2) + (1 + x) * (1 + y) - (let x = y) - (let y = 1) - x;
1 + (let a = (let b = 1) + b) + a + 1;
(let a = (let a = (let a = (let a = 2) + a) + a) + a) - 9;
(let x = 2) ^ (let y = 3);
(let y = 3) ^ (let x = 2); Correct return values are 1, 2, 3, 4, 5, 6, 7, 8, and 9 respectively.
Part 2: Exception Handling
SyntaxError Add Java exception handling to your code by defining two exception classes and
RuntimeError .
let ·A SyntaxError exception should be thrown when an illegal character is found, a closing ) is not found, or a = is not used in a expression.
RuntimeError ·A exception should be thrown when an identifier is encountered for which no value can be found. The exceptions should propagate the error to the main program which prints the diagnostics of the error. You must handle these errors using Java exceptions and the message should be printed by an exception handler in a catch clause.