chapter

    Top-down and Predictive Parsing Practice Questions for Gate Cs

    Solve 172+ Top-down and Predictive Parsing practice 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
    Level 1: Warm-up

    Consider the grammar:

    with terminals and end marker \XYZSAB$ respectively.

    Rank , , from largest to smallest.

    Question 2
    Level 1: Warm-up

    When constructing the LL(1) parsing table, for a production where , the production is added to cell for each terminal in:

    Question 3
    Level 1: Warm-up

    When filling an LL(1) parsing table for a production , which of the following scenarios is IMPOSSIBLE?

    Question 4
    Level 1: Warm-up

    For a grammar that is LL(1), what is the maximum number of productions that can appear in any single cell of its parsing table?

    Question 5
    Level 1: Warm-up
    Consider the following two statements about LL(1) parsing table construction: Assertion (A): For a production , the production is added to for each . Reason (R): The symbol is a terminal and gets its own column in the parsing table. Which of the following is correct?
    Question 6
    Level 1: Warm-up

    What is the minimum number of productions in a context-free grammar with exactly two non-terminals (start symbol) and , such that its LL(1) parsing table contains exactly 5 filled cells (excluding error entries)?

    Question 7
    Level 1: Warm-up

    Consider the standard algorithm for filling an LL(1) parsing table. For a given production , let be the number of table cells that receive this production.

    Consider the following statements about :

    S1:

    S2:

    S3:

    Let be the number of TRUE statements. What is the value of ?

    Question 8
    Level 1: Warm-up

    Consider the context-free grammar with start symbol :

    where the set of terminals is and \$ is the end-marker. Which of the following gives the correct ascending order of the number of filled cells in each row of the LL(1) parsing table?

    Question 9
    Level 1: Warm-up

    Consider the following properties of a context-free grammar:

    \begin{itemize}

    \item P1: The grammar is ambiguous.

    \item P2: The grammar has left recursion.

    \item P3: The grammar has unfactored common prefixes.

    \item P4: The grammar is LL(1).

    \end{itemize}

    How many of these properties, if present in a grammar, guarantee that the grammar is NOT LL(1)?

    Question 10
    Level 1: Warm-up

    Consider the context-free grammar with start symbol :

    where the set of terminals is and \$ is the end-of-input marker.

    The LL(1) parsing table has rows for non-terminals and columns for terminals \{a, b, \\}$. What is the minimum number of cells that must contain a production (not error)?

    Free preview ends here

    Login to view the complete practice 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 Practice Questions for GATE CS

    Solve 172+ Top-down and Predictive Parsing practice 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 (10 Problems)

    Question 1 · Compiler Design MCQ

    Consider the grammar:

    with terminals and end marker \XYZSAB$ respectively.

    Rank , , from largest to smallest.

    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: Count table entries for each non-terminal based on FIRST and FOLLOW sets.

    Step 1: Compute FOLLOW sets:

    • \mathrm{FOLLOW}(S) = \{\\}$ (start symbol)
    • \mathrm{FOLLOW}(A) = \{\\}S \to aAA$ is at the end)
    • \mathrm{FOLLOW}(B) = \{\\}S \to bBB$ is at the end)

    Step 2: Count entries for :

    • : . Add to .
    • : . Add to .

    Step 3: Count entries for :

    • : . Add to .
    • : . \mathrm{FOLLOW}(A) = \{\\}M[A, \.

    Step 4: Count entries for :

    • : . Add to .

    Step 5: Ranking: , , . So .

    Answer: B

    Question 2 · Compiler Design MCQ

    When constructing the LL(1) parsing table, for a production where , the production is added to cell for each terminal in:

    1. A.

      ext{FIRST}(lpha)

    2. B.

    3. C.

    4. D.

      ext{FOLLOW}(lpha)

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This question tests the epsilon production handling rule in parsing table construction. When a production can derive epsilon, we use the FOLLOW set of the left-hand side non-terminal.

    Step 1: Recall the table construction algorithm. For production :

    • Add to for each
    • If , also add to for each

    Step 2: Understand why FOLLOW is used. When can derive , it means can "disappear." The parser needs to know what can follow in the grammar to decide when to apply this production.

    Step 3: Apply the rule. Since , we add to for each .

    Answer:

    Question 3 · Compiler Design MCQ

    When filling an LL(1) parsing table for a production , which of the following scenarios is IMPOSSIBLE?

    1. A.

      cannot derive , and the production is placed in table entries based on .

    2. B.

      can derive , and the production is placed in table entries based on .

    3. C.

      cannot derive , and the production is placed in table entries based on .

    4. D.

      can derive , and the production is placed in table entries based on both and .

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: The FOLLOW set is only used when can derive .

    Step 1: If , then . We place the production in for each . We do NOT use .

    Step 2: If , then . We place the production in for each AND in for each .

    Step 3: Scenario C says cannot derive but we use . This violates the rule: FOLLOW is only used when .

    Step 4: Therefore, C is impossible.

    Answer: C

    Question 4 · Compiler Design MCQ

    For a grammar that is LL(1), what is the maximum number of productions that can appear in any single cell of its parsing table?

    1. A.

      0

    2. B.

      1

    3. C.

      2

    4. D.

      Depends on the grammar

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This question tests the fundamental property of LL(1) grammars — the "1" in LL(1) means we can determine the production by looking ahead 1 symbol, which implies no conflicts in the parsing table.

    Step 1: Recall the definition of LL(1). A grammar is LL(1) if and only if its parsing table has no conflicts — no cell contains more than one production.

    Step 2: Understand what a conflict means. If cell contained two different productions and , the parser wouldn't know which one to apply when it sees non-terminal on top of the stack and terminal as the next input symbol.

    Step 3: Conclude the maximum. Since LL(1) grammars have no conflicts, each cell contains either 0 productions (error entry) or 1 production. The maximum is therefore 1.

    Answer: 1

    Question 5 · Compiler Design MCQ
    Consider the following two statements about LL(1) parsing table construction: Assertion (A): For a production , the production is added to for each . Reason (R): The symbol is a terminal and gets its own column in the parsing table. Which of the following is correct?
    1. A.

      Both A and R are true and R is the correct explanation of A

    2. B.

      Both A and R are true but R is NOT the correct explanation of A

    3. C.

      A is true but R is false

    4. D.

      A is false but R is true

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: This is an assertion-reason question testing understanding of epsilon handling in parsing tables. We need to evaluate both statements independently and check if R explains A.

    Step 1: Evaluate Assertion (A). For production , since , we add to for each . This is correct according to the table construction algorithm. So A is TRUE.

    Step 2: Evaluate Reason (R). The statement claims is a terminal and gets its own column. This is FALSE. is not a terminal — it represents the empty string. The parsing table columns are for actual terminals (from the grammar) plus \\epsilon$.

    Step 3: Since A is true and R is false, the answer is "A is true but R is false."

    Answer: A is true but R is false

    Question 6 · Compiler Design NAT

    What is the minimum number of productions in a context-free grammar with exactly two non-terminals (start symbol) and , such that its LL(1) parsing table contains exactly 5 filled cells (excluding error entries)?

    Correct Answer:

    4.00

    Step-by-Step Solution

    Key idea: this is a reverse-engineering question. We need to find the minimum number of productions that yield exactly 5 filled cells with only 2 non-terminals.

    Step 1: understand the relationship.

    Each production fills cells. To minimize productions, we want each production to fill as many cells as possible.

    Step 2: try 3 productions.

    With and , the most cells we can get from 3 productions:

    • . . . .
    • Row : . Count = 2.
    • Row : , . Union = . Count = 2.
    • Total = 4 cells. Not 5.

    Other 3-production attempts:

    • . Row : 3 cells. Row : 1 cell. Total = 4.
    • . Row : 2 cells. Row : 2 cells. Total = 4.

    Maximum with 3 productions is 4 cells.

    Step 3: try 4 productions.

    • . . . .
    • Row : , . Union = . Count = 3.
    • Row : , . Union = . Count = 2.
    • Total = 5 cells. ✓

    Step 4: verify LL(1).

    , . Disjoint. ✓

    , . Disjoint. ✓

    Answer: 4 productions.

    Question 7 · Compiler Design NAT

    Consider the standard algorithm for filling an LL(1) parsing table. For a given production , let be the number of table cells that receive this production.

    Consider the following statements about :

    S1:

    S2:

    S3:

    Let be the number of TRUE statements. What is the value of ?

    Correct Answer:

    2.00

    Step-by-Step Solution

    Key idea: This is a bounding and statement-truth question. The pivot is handling the -production case correctly.

    Step 1: Analyze S1.

    If , . Since , is TRUE.

    If , . This is also . TRUE.

    Step 2: Analyze S2.

    If and , then can be greater than . So S2 is FALSE in general.

    Step 3: Analyze S3.

    contains at least one terminal or . If it contains , contains at least \k \ge 1$. TRUE.

    Step 4: Count true statements.

    S1 and S3 are true. .

    Answer: 2.00

    Question 8 · Compiler Design MCQ

    Consider the context-free grammar with start symbol :

    where the set of terminals is and \$ is the end-marker. Which of the following gives the correct ascending order of the number of filled cells in each row of the LL(1) parsing table?

    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: this is a parsing-table cell-counting question. The number of filled cells in row equals the size of the union of Predict sets for all productions of .

    Step 1: compute FIRST sets.

    .

    .

    .

    .

    Step 2: compute FOLLOW sets.

    \mathrm{FOLLOW}(S) = \{\\}$.

    : from , after is . . Since is nullable, \mathrm{FOLLOW}(A) \supseteq \mathrm{FOLLOW}(S) = \{\\}\mathrm{FOLLOW}(A) = \{d, \.

    : from , nothing follows . \mathrm{FOLLOW}(B) \supseteq \mathrm{FOLLOW}(S) = \{\\}\mathrm{FOLLOW}(B) = \{\.

    Step 3: count filled cells per row.

    Row : has . Cells: . Count = 1.

    Row : has . has \mathrm{FOLLOW}(A) = \{d, \\}M[A, c], M[A, d], M[A, \. Count = 3.

    Row : has . has \mathrm{FOLLOW}(B) = \{\\}M[B, d], M[B, \. Count = 2.

    Step 4: rank ascending.

    (1) (2) (3).

    Answer: (option B).

    Question 9 · Compiler Design MCQ

    Consider the following properties of a context-free grammar:

    \begin{itemize}

    \item P1: The grammar is ambiguous.

    \item P2: The grammar has left recursion.

    \item P3: The grammar has unfactored common prefixes.

    \item P4: The grammar is LL(1).

    \end{itemize}

    How many of these properties, if present in a grammar, guarantee that the grammar is NOT LL(1)?

    1. A.

      1

    2. B.

      2

    3. C.

      3

    4. D.

      4

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: Certain structural properties make it impossible for a grammar to be LL(1).

    Step 1: P1 (ambiguous) Not LL(1). Every LL(1) grammar must be unambiguous, because ambiguity means some string has multiple parse trees, which implies the parser must choose between productions with the same lookahead, violating the LL(1) disjointness condition.

    Step 2: P2 (left recursion) Not LL(1). If , then includes , so the Predict sets for and other productions of will overlap.

    Step 3: P3 (unfactored common prefixes) Not LL(1). If , then and both contain , causing Predict set overlap.

    Step 4: P4 (is LL(1)) Is LL(1). This property means the grammar IS LL(1), not that it is NOT LL(1).

    Step 5: Properties guaranteeing NOT LL(1): P1, P2, P3.

    Step 6: Count = 3.

    Answer: 3

    Question 10 · Compiler Design MCQ

    Consider the context-free grammar with start symbol :

    where the set of terminals is and \$ is the end-of-input marker.

    The LL(1) parsing table has rows for non-terminals and columns for terminals \{a, b, \\}$. What is the minimum number of cells that must contain a production (not error)?

    1. A.

      1

    2. B.

      2

    3. C.

      3

    4. D.

      4

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This question asks for the minimum number of non-error entries in the parsing table. We need to systematically place each production according to the LL(1) table construction algorithm.

    Step 1: List all productions: and .

    Step 2: Process . Compute . Since , place in . This fills 1 cell.

    Step 3: Process . Compute . Since , place in . This fills 1 more cell.

    Step 4: Count total filled cells. We have and filled. That's 2 cells with productions.

    Step 5: Verify no epsilon productions exist that would add more entries via FOLLOW sets. Neither production derives , so no additional entries.

    Answer: 2

    More practice questions in this unit