Question
Consider the productions and . Each of the five non-terminals , and has two attributes: is a synthesized attribute, and is an inherited attribute. Consider the following rules.
Rule 1:
Rule 2:
Which one of the following is TRUE?
Official answer and solution
- Official answer
- B
- From
- Official GATE 2020 answer key
Solution
Check attribute dependencies against the definition of L-attributed definition.
Definition of L-attributed syntax-directed definition (SDD):
- In every production , each inherited attribute of may depend only on:
- Inherited attributes of the parent .
- Any attributes of symbols to the left of (i.e., ).
- Synthesized attributes of may depend on any attributes of and its children.
Analysis of Rule 1:
- : Inherited attribute depends on parent's inherited attribute . (Valid)
- : Inherited attribute depends on left sibling's attribute and parent's . (Valid)
- : Synthesized attribute depends on children's synthesized attributes. (Valid)
- Thus, Rule 1 is L-attributed.
Analysis of Rule 2:
- Production .
- : Inherited attribute of symbol depends on , an attribute of symbol which appears to the right of .
- Dependencies on right siblings are strictly prohibited in L-attributed grammars.
- Thus, Rule 2 is NOT L-attributed.
Therefore, only Rule 1 is L-attributed.
B
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2020 Computer Science and Information Technology (CS)
- Question
- 43 of 65, printed as CS Q.33
- 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.