chapter

    Top-down and Predictive Parsing Pyqs for Gate Cs

    Solve 6+ Top-down and Predictive Parsing previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    2026 Slot Set1 PYQ
    Level 3: Exam Standard

    Which of the following statements is/are true?

    Question 2
    2025 Slot Set2 PYQ
    Level 3: Exam Standard
    Consider two grammars and with the production rules given below:






    where are the terminals.

    Which of the following option(s) is/are CORRECT?
    Question 3
    2025 Slot Set1 PYQ
    Level 3: Exam Standard

    Which of the following statement(s) is/are <b>TRUE</b> while computing First and Follow during top down parsing by a compiler?

    Question 4
    2024 Slot Set2 PYQ
    Level 3: Exam Standard
    Consider the following context-free grammar where the start symbol is and the set of terminals is . The following is a partially-filled LL(1) parsing table.

    abcd$SS → AaAbS → BbBa(1)(2)AA → ε(3)A → cSB(4)B → εB → dS

    Which one of the following options represents the CORRECT combination for the numbered cells in the parsing table?

    Note: In the options, “blank” denotes that the corresponding cell is empty.
    Question 5
    2024 Slot Set1 PYQ
    Level 3: Exam Standard
    Consider the following grammar , with as the start symbol. The grammar has three incomplete productions denoted by (1), (2), and (3).





    The set of terminals is . The FIRST and FOLLOW sets of the different non-terminals are as follows.

    , ,

    ,

    Which one of the following options CORRECTLY fills in the incomplete productions?
    Question 6
    2021 Slot Set1 PYQ
    Level 3: Exam Standard
    Consider the following context-free grammar where the set of terminals is .


    The following is a partially-filled LL(1) parsing table.

    ① ②
    ③ ④

    Which one of the following choices represents the correct combination for the numbered cells in the parsing table (“blank” denotes that the corresponding cell is empty)?
    Free preview ends here

    Login to view the complete previous-year questions and solutions

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Explore complete test series, official past papers, and chapter-wise study tools.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Top-down and Predictive Parsing PYQs for GATE CS

    Solve 6+ Top-down and Predictive Parsing previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: Top-Down and Predictive Parsing

    Chapter · Top-Down and Predictive Parsing
    Three topics, one engine
    From "what can start a string" to "which table cell to fill".
    01
    FIRST and FOLLOW Set Computation
    This topic · moderate weight · 2 PYQs in this course
    Build the two foundational sets that make predictive parsing possible. By the end you will compute FIRST and FOLLOW for any CFG by hand.
    02
    LL(1) Grammar Conditions and Predictive Parsing
    Moderate weight · 2 PYQs in this course
    Use FIRST and FOLLOW to decide whether a grammar is LL(1). Master the disjointness condition that removes ambiguity in top-down choices.
    03
    LL(1) Parsing Table Construction
    Moderate weight · 2 PYQs in this course
    Turn the disjointness condition into a concrete table. Fill entries, detect conflicts, and read off parse steps.
    By the end of this chapter you will
    • Compute FIRST and FOLLOW sets for any CFG in under two minutes.
    • Decide in one glance whether a grammar is LL(1) or not.
    • Build the full LL(1) parsing table and trace a derivation.

    What are FIRST and FOLLOW, and why do they exist?

    A top-down parser expands non-terminals one at a time. At each step it must pick a production. To pick correctly while reading the input only once, it needs two pieces of information about every non-terminal :

    FIRST of

    The set of terminals that can appear at the very beginning of a string derived from .

    FOLLOW of

    The set of terminals that can appear immediately to the right of in some sentential form.

    Together they answer the parser's only real question:

    "Given that I am about to expand , and the next input token is , which production of should I use?"

    If the grammar is well-behaved (LL(1)), the answer is unique. Computing FIRST and FOLLOW is the first step toward checking that, and toward building the parsing table.

    Top-down and Predictive Parsing: Solved Questions with Step-by-Step Explanations (6 Problems)

    Question 1 · Compiler Design · 2026_Set1 MSQ

    Which of the following statements is/are true?

    1. A.

      LL(1) parser uses backtracking

    2. B.

      For a grammar to be LL(1), it must be left-recursive

    3. C.

      For a grammar to be LL(1), it must be left-factored

    4. D.

      The LL(1) parsers are more powerful than the SLR parsers

    Correct Answer:

    ["C"]

    Step-by-Step Solution

    Insight: LL(1) parsers are predictive and non-backtracking. They require grammars to be free of left recursion and left-factored to avoid FIRST set conflicts.

    Exam route: Evaluate each statement against the core properties of LL(1) grammars and parser hierarchy.

    Learning route:

    Step 1: Evaluate Option A. LL(1) parsers are predictive; they use the parsing table to make deterministic choices without backtracking. FALSE.

    Step 2: Evaluate Option B. Left recursion causes infinite loops in top-down parsing and guarantees FIRST-FIRST conflicts. It must be eliminated, not required. FALSE.

    Step 3: Evaluate Option C. If a grammar has common prefixes (e.g., ), their FIRST sets will overlap, violating the LL(1) disjointness condition. Left factoring is the necessary transformation to resolve this. TRUE.

    Step 4: Evaluate Option D. The parser power hierarchy is LL(1) SLR LALR CLR. SLR is strictly more powerful than LL(1). FALSE.

    Conclusion: Only Option C is true.

    Question 2 · Compiler Design · 2025_Set2 MSQ
    Consider two grammars and with the production rules given below:






    where are the terminals.

    Which of the following option(s) is/are CORRECT?
    1. A.

      is not and is .

    2. B.

      is and is not .

    3. C.

      and are not .

    4. D.

      and are ambiguous.

    Correct Answer:

    ["C"]

    Step-by-Step Solution

    Insight: is the classic ambiguous dangling-else grammar. resolves the ambiguity but introduces a FIRST-FIRST conflict, making it non-LL(1).

    Exam route: Check for ambiguity. Check for LL(1) disjointness by computing FIRST sets of 's productions.

    Learning route:

    Step 1: Analyze . The string if b then if b then a else a has two valid leftmost derivations (the else can bind to the first or second if). Thus, is ambiguous. Since no ambiguous grammar can be LL(1), is not LL(1).

    Step 2: Analyze . This is a transformed grammar intended to resolve the dangling-else ambiguity by forcing else to bind to the innermost if (via ). So is unambiguous.

    Step 3: Check if is LL(1). Look at productions for : and .

    Step 4: Compute FIRST sets for these productions.

    • FIRST(if E then S) = .
    • FIRST() = FIRST(if E then M else S) FIRST() = .

    Step 5: Check disjointness. FIRST(if E then S) FIRST() = .

    Step 6: Because of this FIRST-FIRST conflict, the parser cannot decide whether to use or when the lookahead is if. Thus, is not LL(1).

    Conclusion: Both and are not LL(1). Option C is correct.

    Question 3 · Compiler Design · 2025_Set1 MSQ

    Which of the following statement(s) is/are <b>TRUE</b> while computing First and Follow during top down parsing by a compiler?

    1. A.

      For a production , will be added to .

    2. B.

      If there is any input right end marker, it will be added to , where is the start symbol.

    3. C.

      For a production , will be added to .

    4. D.

      If there is any input right end marker, it will be added to , where is the start symbol.

    Correct Answer:

    ["A","D"]

    Step-by-Step Solution

    Insight: FIRST sets can contain if a production derives it, but FOLLOW sets strictly contain only terminals and the end-marker \$.

    Exam route: Evaluate each statement against the formal definitions of FIRST and FOLLOW sets.

    Learning route:

    Step 1: Evaluate Option A. For , by definition, FIRST(). This is TRUE.

    Step 2: Evaluate Option B. The end-marker \SSSS$. This is FALSE.

    Step 3: Evaluate Option C. FOLLOW sets represent terminals that can appear immediately to the right of a non-terminal. is not a terminal and is never added to any FOLLOW set. This is FALSE.

    Step 4: Evaluate Option D. By the end-marker convention, \SS$. This is TRUE.

    Conclusion: Options A and D are true.

    Question 4 · Compiler Design · 2024_Set2 MCQ
    Consider the following context-free grammar where the start symbol is and the set of terminals is . The following is a partially-filled LL(1) parsing table.

    abcd$SS → AaAbS → BbBa(1)(2)AA → ε(3)A → cSB(4)B → εB → dS

    Which one of the following options represents the CORRECT combination for the numbered cells in the parsing table?

    Note: In the options, “blank” denotes that the corresponding cell is empty.
    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    A

    Step-by-Step Solution

    Insight: The parsing table is filled using FIRST sets for direct terminals and FOLLOW sets when a production derives .

    Exam route: Compute FOLLOW(A) and FOLLOW(B) by looking at what immediately follows them in the RHS of . Then apply the -rule for cells (3) and (4).

    Learning route:

    Step 1: Identify productions for : and .

    Step 2: Compute FIRST sets. FIRST() = (since ). FIRST() = .

    Step 3: Cell (1) is M[]. Since FIRST(), we place here.

    Step 4: Cell (2) is M[]. Since FIRST(), we place here.

    Step 5: Compute FOLLOW sets. In , the first is followed by , and the second is followed by . Thus, FOLLOW() = . Similarly, FOLLOW() = .

    Step 6: Cell (3) is M[]. Since and FOLLOW(), we place here.

    Step 7: Cell (4) is M[]. Since and FOLLOW(), we place here.

    Conclusion: (1) , (2) , (3) , (4) .

    Question 5 · Compiler Design · 2024_Set1 MCQ
    Consider the following grammar , with as the start symbol. The grammar has three incomplete productions denoted by (1), (2), and (3).





    The set of terminals is . The FIRST and FOLLOW sets of the different non-terminals are as follows.

    , ,

    ,

    Which one of the following options CORRECTLY fills in the incomplete productions?
    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    A

    Step-by-Step Solution

    Insight: This is a reverse-engineering question. You must deduce the missing productions by matching the given FIRST and FOLLOW sets, paying special attention to nullable non-terminals.

    Exam route: Check FIRST(S) to eliminate options B and C. Check FIRST(T) to eliminate option D. Verify the remaining option A against FOLLOW sets.

    Learning route:

    Step 1: Analyze FIRST(S). The production is . We know . Since the given , the missing production (1) must contribute to the FIRST set.

    Step 2: Evaluate (1) in the options.

    • If (1) is : Since , . This perfectly matches the requirement.
    • If (1) is : . This would make , missing .

    Thus, (1) must be . This eliminates options B and C.

    Step 3: Analyze FIRST(T). The production is . We know and . Since the given , production (2) must contribute and no other terminals.

    Step 4: Evaluate (2) in the remaining options (A and D).

    • If (2) is : . This matches perfectly.
    • If (2) is : . This would add to , contradicting the given set.

    Thus, (2) must be . This eliminates option D.

    Step 5: Verify (3) in Option A. The production is . Given , production (3) must start with . Option A gives , which has . This matches.

    Step 6: Verify FOLLOW sets for Option A to be absolutely certain.

    • : appears in (followed by ) and (at the end). Thus, . Matches!
    • : appears in . It is followed by , so gets . Since is nullable, also gets . Thus contains .
    • : is the start symbol, so \\text{FOLLOW}(S)ST \rightarrow aS\text{FOLLOW}(S)\text{FOLLOW}(T)\text{FOLLOW}(S) = \text{FOLLOW}(T) = \{c, f, \. Matches perfectly!

    Conclusion: Option A is the only mathematically consistent choice.

    Question 6 · Compiler Design · 2021_Set1 MCQ
    Consider the following context-free grammar where the set of terminals is .


    The following is a partially-filled LL(1) parsing table.

    ① ②
    ③ ④

    Which one of the following choices represents the correct combination for the numbered cells in the parsing table (“blank” denotes that the corresponding cell is empty)?
    1. A.

      ①  ②  ③  ④

    2. B.

      ① blank ②  ③  ④

    3. C.

      ①  ② blank ③ blank ④

    4. D.

      ① blank ②  ③ blank ④ blank

    Correct Answer:

    A

    Step-by-Step Solution

    Insight: When a non-terminal follows and can derive , FIRST() \ {} becomes part of FOLLOW().

    Exam route: Compute FOLLOW() carefully by tracing . Then apply the -rule for in columns and \$.

    Learning route:

    Step 1: Analyze . FIRST() = . Thus, FIRST() = .

    Step 2: Cell ① is M[]. Since FIRST(), place here.

    Step 3: Cell ② is M[]. Since FIRST(), place here.

    Step 4: Compute FOLLOW().

    • From , FOLLOW() FOLLOW(), so \ \inT$).
    • From , is followed by . Thus, FIRST() \ {} FOLLOW(). Since FIRST() = , we get FOLLOW().
    • Therefore, FOLLOW() = \{c, f, \\}fR \rightarrow \epsilonR\subseteqTRfS \rightarrow Rf$).

    Step 5: Cell ③ is M[]. Since FOLLOW() and is a production, place here.

    Step 6: Cell ④ is M[T, \]\ FOLLOW(), place here.

    Conclusion: ① , ② , ③ , ④ .

    More previous year questions (pyqs) in this unit