Consider the syntax directed definition shown below.Here, is a function that generates the output code, and is a function that returns the name of a new temporary variable on every call. Assume that s are the temporary variable names generated by . For the statement the -address code sequence generated by this definition is
View worked solution
Answer: B
To find the 3-address code generated for the statement , we construct the parse tree and evaluate the semantic actions bottom-up.
1. Parse Tree Construction
The parse tree for the expression is:
- (where is )
-
- (where is )
- (where is )
-
2. Bottom-Up Evaluation of Semantic Actions
-
For the leaf nodes:
- (with ):
- (with ):
- (with ):
-
For the production :
- A new temporary variable is created:
- The code generation function is called:
- The place attribute is synthesized:
-
For the production (with ):
- The code generation function is called:
- The code generation function is called:
3. Final Generated Code
Combining the generated statements in order of their execution, we get:
This matches Option B.
Free practice · Your answers on this page are not saved.
