Consider the following translation scheme.
Here is a token that represents an integer and represents the corresponding integer value. For an input this translation scheme prints
View worked solution
Answer: D
To find the output of the translation scheme for the input , we construct the parse tree and execute the semantic actions during a depth-first (post-order) traversal.
The parse tree for the input string is structured as follows:
Performing a depth-first traversal, the semantic actions are executed in the following order:
- Under , the token is matched: prints
2 - Under , the token is matched: prints
3 - Under , the token is matched: prints
4 - The action in is executed: prints
+ - The action in is executed: prints
*
Combining the printed values in order of execution gives: 2 3 4 + *.
Free practice · Your answers on this page are not saved.
