GATE CS 2025 Set 2 — Question 22
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.MCQ+1 / -0.33MediumS- & L-Attributed GrammarsSemantic AnalysisCompiler Design
Compiler Design → Semantic Analysis → S- & L-Attributed Grammars
Last updated
Question
Given the following syntax directed translation rules:Rule 1:
Rule 2:
Rule 3: Which ONE is the CORRECT option among the following?
Rule 2:
Rule 3: Which ONE is the CORRECT option among the following?
Correct answer
(C) Rule 1 is neither S-attributed nor L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed
Solution
To determine if the rules are S-attributed or L-attributed, we analyze the dependencies of the attributes:Definitions:
- S-attributed: Only uses synthesized attributes (attributes of the LHS depend on attributes of the RHS symbols).
- L-attributed: Attributes can be synthesized or inherited. Inherited attributes of a symbol on the RHS can only depend on attributes of the LHS (parent) or attributes of symbols to its left.
- : inherits from parent . Allowed in L-attributed.
- : inherits from . In the production
R → AB, is to the right of . An inherited attribute depending on a right sibling is NOT allowed in L-attributed definitions. - Since it uses inherited attributes, it is NOT S-attributed.
- Conclusion: Rule 1 is neither S-attributed nor L-attributed.
- : Synthesized attribute. Allowed in both.
- : inherits from . In
P → CD, is to the left of . This dependency is allowed in L-attributed definitions. - Since is an inherited attribute (computed before the node is fully processed), it is NOT S-attributed.
- Conclusion: Rule 2 is L-attributed but not S-attributed.
- : Synthesized attribute. No inherited attributes are present.
- Conclusion: Rule 3 is S-attributed (and by definition, all S-attributed definitions are also L-attributed).
- Rule 1: Neither S nor L.
- Rule 2: Not S, is L.
- Rule 3: S and L.
Continue learning with Success Tracker
A step still unclear? Work through it with support
Use Success Tracker to ask about the reasoning, then try another GATE CS question to check your understanding.
AI-powered practice· Unlimited practice on eligible plans
- PYQs with solutions
- Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
- Practice that adapts
- Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
- AI doubt support
- Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.
Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.
This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.
More questions on Semantic Analysis
2026 Set 2 Q17In C runtime environment, which one of the following is stored in heap?2026 Set 2 Q19Consider the following three ANSI-C programs, P1, P2, and P3. P1 [code] P2 [code] **P3**…2026 Set 1 Q27Consider the following C statements: Which of the following options is/are correct? [figure]2026 Set 1 Q28Which of the following statements is/are true?2026 Set 2 Q35A lexical analyzer uses the following token definitions - - …