For this assignment, you are to extend your SILLY interpreter to handle conditionals and loops. The expanded grammar rules for the SILLY language are as follows:
As stated in HW3, the SILLY language is case sensitive, and variables are not explicitly declared and are assumed to have value 0 if not otherwise assigned. The new conditional statement performs a less-than comparison, executing the statement(s) preceding "endif" if the comparison evaluates to true. Similarly, the new loop statement performs a less-than comparison, repeatedly executing the statement(s) preceding "endwhile" as long as the comparison evaluates to true.
As before, your SILLY interpreter should read the program from standard input (i.e., cin) and display the output that would be produced by the SILLY program. If there are any syntax errors in the program, the interpreter should display "SYNTAX ERROR" and halt. For example:
SAMPLE PROGRAM OUTPUT start x = 10 if x < 20 output "x is" output x endif output "done" end x is 10 done start L = 1 s = 0 while L < 6 s = s + L L = L + 1 output s endwhile end 1 3 6 10 15
Note: since conditionals and loops are both statements, it is perfectly legal to nest these control statements. For example, a program might contain a conditional inside a loop, or a loop inside a conditional, or even a loop inside a conditional inside a loop! Be sure to consider the possibility of arbitrarily nested statements as you design your solution to this problem.