Consider the following SLang 1 program:
expression
Recall that there are 5 types of expressions in SLang 1 and that the main function in the interpreter is structured around these 5 cases. In this problem, you must determine how many times each case is evaluated when the SLang 1 program above is interpreted in a global environment in which x, y, and z are bound to the values 1, 2, and 3, respectively.
Fill in your answer below, one count per box.
# of integer expressions evaluated: | |
# of variable expressions evaluated: | |
# of function expressions evaluated: | |
# of application expressions evaluated: | |
# of primitive application expressions evaluated: |
If the interpretation of the program generates a runtime error, then the correct answer is the set of all correct count values accumulated up to and including the case that threw the exception.
Counting the number of each type of expressions in the given program gives you an upper bound on the possible values for each count.
Why does counting the number of each type of expressions in the given program not necessarily yield the correct answer to this problem?
Because of the answer to the previous hint/question and the possibility of runtime errors, it is imperative that you not only understand each case individually but also the order in which they apply.
You should study the code for each one of the 5 cases of the main function in the interpreter.js file until you can trace the code for each case correctly in your head.
Make sure to leave no boxes empty. Each box MUST contain an integer, even when the correct count is 0.