Description
These will be the exception test cases: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.
1 + (2 * 3; // syntax error: ‘)’ expected (let x 5) + x; // syntax error: ‘=’ expected
(let x = 5) (let y = 6); // syntax error: operator expected
(let x = 5 let y = 6); // syntax error: ‘)’ expected
(ler x = 5) ^ (let y = 6); // runtime error: ‘ler’ undefined (let x = 5) + y; // runtime error: ‘y’ undefined
A Working Procedure Example
| Expression | Stack | Pop & Return | H | ||||||||||||||
| 1 | 1 + |
|
/ | < | |||||||||||||
| 2 | 1 + (let x = 1 |
|
/ | x | |||||||||||||
| 3 | 1 + (let x = 1) |
|
1
(returned from “let x = 1”) |
x | |||||||||||||
| 4 | 1 + (let x = 1) + (let y = 2) + (1 + x * (1 + y |
|
/
(“let y = 2” has already returned 2) |
x y | |||||||||||||
| 5 | 1 + (let x = 1) + (let y = 2) + (1 + x * (1 + y) |
|
3
(returned from “1 + y”) |
x y | |||||||||||||
| 6 | 1 + (let x = 1) + (let y = 2) + (1 + x * (1 + y)) – (let x = y |
|
/
(“1 + x * 3” has already returned 4) |
x y | |||||||||||||
| 7 | 1 + (let x = 1) + (let y = 2) + (1 + x * (1 + y)) – (let x = y) – x |
|
/
(“let x = y” has already returned 2) |
x y | |||||||||||||
Em
=
=
=
=
=
=
=
=
=
=
| 8 | 1 + (let x = 1) + (let y = 2) + (1 + x * (1 + y)) – (let x = y) – x; | <Empty> | 4 | x y |
=
=
Calculator.java



