Question
Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let and be the placeholders for the non-terminals or in the following table:
| Production rule | Semantic action |
|---|---|
Which one of the following are the appropriate choices for and ?
Official answer and solution
- Official answer
- A
- From
- Official GATE 2019 answer key
Solution
Track how type information flows from production head to children in syntax-directed translation schemes.
In syntax-directed translation schemes for variable declarations:
- For the declaration rule :
The non-terminal synthesizes a type attribute ( or ). This type must be inherited by the identifier list . Therefore, the semantic action is:Comparing with , we obtain and .
- For the identifier list rule :
The list must inherit the exact same type attribute that was passed down to . Therefore, the semantic action is:Comparing with , we obtain and .
Thus, the appropriate choices are (Option A).
A
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2019 Computer Science and Information Technology (CS)
- Question
- 46 of 65, printed as CS Q.36
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.