GATE CS 2026 Set 1 — Question 53
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.MSQ+2 / -0MediumS- & L-Attributed GrammarsSemantic AnalysisCompiler DesignSyntax-Directed TranslationSymbol Tables
Compiler Design → Semantic Analysis → S- & L-Attributed Grammars
Last updated
Question
Consider the following two syntax-directed definitions SDD1 and SDD2 for type declarations.
is the start symbol, and , and are the three terminals. The non-terminal is the same as and the non-terminal is the same as . Here, the subscript is used to differentiate the grammar symbols on the two sides of a production. The function updates the symbol table with the type information for an identifier.Let P and Q be the languages specified by grammars G1 and G2, respectively.Which of the following statements is/are true?
SDD1
| Grammar (G1) | Semantic Rules |
|---|---|
| | |
| | |
SDD2
| Grammar (G2) | Semantic Rules |
|---|---|
| | |
| | |
Correct answer
(A) The languages P and Q are the same; (B) SDD2 is S-attributed and contains only synthesized attributes; (D) The specifications of SDD1 and SDD2 are such that the same entries get added to the symbol table
Solution
(A) Languages. In G1, derives for , so gives (), where is or . In G2, is left-recursive and also derives with identifiers. Hence . True.(B) SDD2. Every attribute in SDD2 (, ) is computed from attributes of the children of the production (, , ). So all attributes are synthesized and SDD2 is S-attributed. True.(C) SDD1. and are inherited (they come from the sibling or the parent ), so SDD1 is indeed L-attributed. But and are synthesized, so it does not contain only inherited attributes. False.(D) Symbol-table entries. For a declaration :
- SDD1 passes down the chain of 's, and each calls .
- SDD2 propagates up the chain of 's (), and each production calls .
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: [figure] Which of the following options is/are correct?2026 Set 1 Q28Which of the following statements is/are true?2026 Set 2 Q35A lexical analyzer uses the following token definitions - - …