GateAI

GATE CSE Parsing PYQs

Medium yield28.1% of Compiler Design

GATE heavily tests the Parsing stage of compiler design across both Top-Down (LL(1), recursive descent) and Bottom-Up (LR(0), SLR(1), LALR(1), CLR(1)) paradigms… Read the guide

Questions
23
Asked
since 2012
Total marks
38
Marks / paper
1.5

23 GATE CSE Parsing PYQs with solutions, from Compiler Design. Browse all GATE CSE PYQs.

Questions

Every official paper that asked this topic, newest first.

What GATE tests in Parsing

Concepts, patterns, formulas and traps distilled from past papers.

GATE heavily tests the Parsing stage of compiler design across both Top-Down (LL(1), recursive descent) and Bottom-Up (LR(0), SLR(1), LALR(1), CLR(1)) paradigms. Key evaluation areas include computing FIRST and FOLLOW sets to populate parsing tables, detecting conflicts (Shift-Reduce, Reduce-Reduce), classifying grammars within the parsing power hierarchy, and executing item-set closure/goto operations. In recent years, items have shifted toward exact item counting via GOTO/CLOSURE in NAT format, reverse engineering grammar rules from FIRST/FOLLOW sets, and multi-concept MSQ verification.

Core concepts

  • FIRST and FOLLOW set calculation
  • LL(1) parsing table construction and conflict resolution
  • Elimination of direct and indirect left recursion
  • Left factoring and non-backtracking predictive parsing
  • LR(0) canonical items, CLOSURE, and GOTO function computation
  • SLR(1) parsing table construction using FOLLOW sets
  • LR(1) / CLR(1) items with propagated lookaheads
  • LALR(1) core-merging criteria and generation of Reduce-Reduce conflicts
  • Shift-Reduce (S-R) vs Reduce-Reduce (R-R) conflicts
  • Parsing power hierarchy: LL(1) ⊂ SLR(1) ⊂ LALR(1) ⊂ CLR(1)
  • Ambiguity in grammars (e.g., dangling-else) and its impact on determinism
  • Operator precedence and associativity derived from recursive productions
  • Computation of FIRST sets for non-terminals and production right-hand sides
  • Computation of FOLLOW sets with transitive/mutual dependencies
  • Handling of -productions during LL(1) parse table construction
  • Handling end-marker \$ in the start symbol's FOLLOW set
  • Detection of multiple entries/conflicts (FIRST/FOLLOW or FIRST/FIRST conflicts)
  • Augmented CFG construction
  • LR(0) items representation
  • Closure operation in LR parsing
  • Goto transition computation in LR parsing automata

Recurring question patterns

  • Canonical LR Item and GOTO Set State Construction

    CommonNAT2 marks2024, 2021

    Given an augmented grammar, compute the CLOSURE of an initial set and evaluate multi-step GOTO transitions to count the exact number of items in a resulting state.

  • Grammar Classification in the LR/LL Hierarchy

    CommonMCQ2 marks2025, 2022, 2015

    Determine whether a given context-free grammar is LL(1), SLR(1), LALR(1), or CLR(1) by identifying specific conflicts (FIRST/FIRST, FIRST/FOLLOW, Shift-Reduce, or Reduce-Reduce) across states.

  • FIRST/FOLLOW Computation and LL(1) Table Population

    CommonMCQ2 marks2024

    Compute FIRST and FOLLOW sets to fill in blank cells of an LL(1) parsing table or reconstruct missing grammar productions from given FIRST/FOLLOW constraints.

  • Conflict Detection in LR Item Sets

    CommonMCQ2 marks2026, 2014, 2013

    Analyze either a single canonical item set or all states of an LR(0)/SLR(1)/LALR(1) automaton to count or identify Shift-Reduce (S-R) or Reduce-Reduce (R-R) conflicts under specific lookaheads.

  • Grammar Transformations: Left Recursion and Associativity

    CommonMCQ1 marks2017, 2016, 2014

    Identify direct/indirect left recursion, convert left-recursive grammars to right-recursive forms, or derive operator precedence/associativity directly from grammar structure.

  • Theoretical Properties and Hierarchy of Parsers

    OccasionalMSQ1 marks2026, 2024, 2022, 2021

    Evaluate conceptual assertions concerning deterministic CFGs, parser power comparisons (LL vs SLR vs LALR vs CLR), parsing time complexity (e.g., CYK O(n3)O(n^3)), and state merging rules.

  • FIRST and FOLLOW Set Computation

    CommonMCQ2 marks2012

    Given a context-free grammar with nullable productions and cyclic or mutual dependencies (e.g., non-terminals deriving the start symbol), compute the exact FIRST and FOLLOW sets for specified non-terminals.

  • LL(1) Parsing Table Population

    CommonMCQ2 marks2012

    Given a grammar and its FIRST/FOLLOW sets (or as a multi-part follow-up), identify specific entries M[A,a]M[A, a] in the LL(1) parsing table, testing whether candidates apply the rule for epsilon-deriving productions mapping to FOLLOW sets.

  • Computation of LR(0) Goto and Closure Item Sets

    RareNAT1 marks2022

    Given an augmented Context-Free Grammar (CFG) and a base set of LR(0) items, compute the cardinality (total count of distinct items) of a resulting LR(0) state after applying closure and goto transitions on a specified terminal or non-terminal symbol.

Formulas GATE uses

Maximum Bottom-Up Reductions

Max Reductions=n−1\text{Max Reductions} = n - 1

Used when parsing a string of nn tokens with a bottom-up parser on a grammar containing no ϵ\epsilon-productions and no unit-productions.

Immediate Left Recursion Elimination

A→Aα∣β  ⟹  A→βA′,A′→αA′∣ϵA \rightarrow A\alpha \mid \beta \implies A \rightarrow \beta A^{\prime}, \quad A^{\prime} \rightarrow \alpha A^{\prime} \mid \epsilon

Used to transform directly left-recursive productions into equivalent right-recursive productions suitable for top-down LL(1) parsing.

General Context-Free Parsing Worst-Case Time

T(n)=O(n3)T(n) = O(n^3)

Used to denote the worst-case time complexity of universal CFG parsers (e.g., CYK or Earley's algorithm) for a string of length nn.

LALR State Merge Condition

Core(Ij)=Core(Ik)  ⟺  {A→α⋅β∣[A→α⋅β,a]∈Ij}={A→α⋅β∣[A→α⋅β,b]∈Ik}\text{Core}(I_j) = \text{Core}(I_k) \iff \{A \rightarrow \alpha\cdot\beta \mid [A \rightarrow \alpha\cdot\beta, a] \in I_j\} = \{A \rightarrow \alpha\cdot\beta \mid [A \rightarrow \alpha\cdot\beta, b] \in I_k\}

Used to determine if two LR(1) item sets can be merged to form a single LALR(1) state.

FOLLOW Set Propagation Rule

FOLLOW(B)=⋃A→αBβ((FIRST(β)∖{ε})∪(if ε∈FIRST(β) then FOLLOW(A)))\text{FOLLOW}(B) = \bigcup_{A \rightarrow \alpha B \beta} ((\text{FIRST}(\beta) \setminus \{\varepsilon\}) \cup (\text{if } \varepsilon \in \text{FIRST}(\beta) \text{ then } \text{FOLLOW}(A)))

Used when determining the terminal symbols that can appear immediately to the right of a non-terminal BB across all sentential forms.

LL(1) Parsing Table Construction Rule

For A→α:  ∀a∈FIRST(α)∖{ε},  M[A,a]←A→α;if ε∈FIRST(α),  ∀b∈FOLLOW(A),  M[A,b]←A→α\text{For } A \rightarrow \alpha:\; \forall a \in \text{FIRST}(\alpha) \setminus \{\varepsilon\},\; M[A, a] \leftarrow A \rightarrow \alpha;\quad \text{if } \varepsilon \in \text{FIRST}(\alpha),\; \forall b \in \text{FOLLOW}(A),\; M[A, b] \leftarrow A \rightarrow \alpha

Used to place production A→αA \rightarrow \alpha into table cells M[A,t]M[A, t] for terminals and the end-marker \.

LR(0) Closure Function

closure(I)=I∪{[B→.γ]∣[A→α.Bβ]∈closure(I),B→γ∈G}\text{closure}(I) = I \cup \{[B \rightarrow .\gamma] \mid [A \rightarrow \alpha . B \beta] \in \text{closure}(I), B \rightarrow \gamma \in G\}

Used recursively whenever the dot directly precedes a non-terminal symbol in any LR(0) item of the set.

LR(0) Goto Function

goto(I,X)=closure({[A→αX.β]∣[A→α.Xβ]∈I})\text{goto}(I, X) = \text{closure}(\{[A \rightarrow \alpha X . \beta] \mid [A \rightarrow \alpha . X \beta] \in I\})

Used to compute the transition state on terminal or non-terminal XX from an item set II.

Examiner traps in Parsing

  • Assuming LALR(1) state merging can introduce Shift-Reduce conflicts (it can only introduce Reduce-Reduce conflicts).
  • Placing LR(0) reduce actions only under FOLLOW sets instead of under all input terminals (SLR places in FOLLOW, LR(0) places in all columns).
  • Forgetting to include transitions when computing CLOSURE for non-terminals that derive (resulting in undercounting items).
  • Overlooking indirect left recursion (e.g., S → Aa with A → Sc).
  • Assuming an ambiguous grammar can be parsed by an LR(1) or LL(1) parser; any ambiguous grammar fails all deterministic parser checks.
  • Failing to carry forward lookahead symbols when expanding non-terminals in LR(1) closure calculations ([A → · B , a] gives lookahead FIRST( a)).
  • Forgetting to include \ in FOLLOW(S) for the start symbol S$.
  • Omitting FOLLOW(A) when propagating to FOLLOW(B) if A → B with nullable or B as the rightmost symbol.
  • Failing to propagate FOLLOW sets through cyclic derivations (e.g., A → S implies FOLLOW(A) ⊆ FOLLOW(S)).
  • Placing an -production in table cells corresponding to its FIRST set rather than the LHS non-terminal's FOLLOW set.
  • Confusing the LHS non-terminal of an indirect derivation (e.g., writing S → into M[B, a] instead of B → S when B ⇒* ).
  • Forgetting transitive/recursive closure expansion when added productions also have a dot before a non-terminal (e.g., expanding R introduces [R → .P], which must then trigger adding productions of P).
  • Including items where the dot shift does not match the transition symbol.
  • Off-by-one errors by counting the shifted kernel item only and omitting the newly generated closure items.

How questions are asked

  • Compute item count in a state after sequential GOTO operations
  • Identify grammar membership within LR(0)/SLR(1)/LALR(1)/CLR(1)/LL(1)
  • Fill missing entries in an LL(1) parsing table
  • Reconstruct missing grammar rules given FIRST and FOLLOW sets
  • Count total number of Shift-Reduce or Reduce-Reduce conflicts in an ACTION table
  • Evaluate operator precedence and associativity from grammar or tabular attributes
  • Identify direct/indirect left recursion elimination correctness
  • Compute FIRST and FOLLOW sets for non-terminals
  • Identify entries in specific LL(1) parsing table cells M[A, t]
  • Count the number of conflicts/multiple entries in an LL(1) parse table
  • Count items in goto(closure(I), X) for a given grammar snippet

Paper trends

  • Shift from basic declarative MCQs on parser power to procedural NAT questions requiring exact item counts after multiple GOTO and CLOSURE steps.

    2024, 2021

  • Increased use of MSQ formats to simultaneously test parser definitions, non-backtracking nature of predictive parsers, left-factoring necessities, and grammar ambiguity.

    2026, 2025, 2024

  • Introduction of inverse/constraint-satisfaction problems, such as reconstructing missing production rules from partial grammars and complete FIRST/FOLLOW sets.

    2024

  • LL(1) parsing questions in 2012 were posed as linked 2-mark MCQs that chained FIRST/FOLLOW evaluation directly into parse table cell verification.

    2012

  • Direct calculation of LR parsing sub-routines (e.g., goto/closure sizes) is tested as an exact-integer NAT question without requiring full DFA construction.

    2022

Difficulty notes

Easy questions (1 mark) test parser definitions (Top-Down vs Bottom-Up), standard operator precedence/associativity evaluations, or immediate left recursion identification. Medium questions (2 marks) require multi-step procedural computations: building LR item graphs, computing CLOSURE and GOTO, tracking exact lookahead sets to differentiate SLR(1) from LALR(1), counting table conflicts, or completing partially filled LL(1) tables from FIRST/FOLLOW sets.