The SILLY interpreter you wrote for HW2 extended the starter version to include missing features (operators, local variables and repeat statements). For this third SILLY assignment, you are to further extend your interpreter to implement if and break statements.
To complete this assignment, you must do the following:
SAMPLE CODE (output in red) >>> if true then print "howdy" endif "howdy" >>> var num gets 87 >>> print num 87 >>> if ((num > 90) | (num = 90)) then print "A" elseif ((num > 80) | (num = 80)) then print "B" elseif ((num > 70) | (num = 70)) then print "C" elseif ((num > 60) | (num = 60)) then print "D" else print "F" endif "B" >>> repeat 5 times print 1 if true then print 2 break print 3 endif print 4 endrepeat 1 2>>> repeat 3 times print "before" var num gets 10 while (num < 50) do print num if (num > 20) then print "breaking" break endif num gets (10 + num) endwhile print "after" endrepeat "before" 10 20 30 "breaking" "after" "before" 10 20 30 "breaking" "after" "before" 10 20 30 "breaking" "after"
If class that that inherits from Statement and provides the required methods for an if statement. As you saw from the grammar rules in HW1, an if statement can have an arbitrary number of elseif cases and an optional else case. Your class will have to accommodate all these forms. If the syntax of the statement does not follow the grammar rules, an exception should be thrown with a meaningful (syntax) error message. Similarly, if the test does not evaluate to a Boolean value, an exception should be thrown with a meaningful (runtime) error message. Break class that that inherits from Statement and provides the required methods for a break statement. Similar to how breaks work in Java, executing a SILLY break statement should terminate the enclosing loop (while or repeat). Hint: this addition will make it clear why the execute method of a statement has a return value. The execute method for Break should return Statement.Status.BREAK to denote that a break has been executed. This return value can then be used by the other statement classes to determine whether execution should be terminated or not. nums = [4 2 10 -1 800]
then your code would display the list:
[3 16 "yes"]
If the first line was:
nums = [1 3 0 5]
then your code would display the list:
[4 9 "no"]
Save your SILLY code in a text file named hw3.txt and submit it along with your project code.