chapter

    Bottom-up and Lr Parsing Pyqs for Gate Cs

    Solve 8+ Bottom-up and Lr 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 Set2 PYQ
    Level 3: Exam Standard
    Consider the canonical parsing of the grammar below using terminals and non-terminals with as the start symbol.





    Which one of the following options gives the number of shift-reduce conflicts that will occur in the ACTION table?
    Question 2
    2025 Slot Set2 PYQ
    Level 3: Exam Standard
    Given a Context-Free Grammar as follows:





    Which ONE of the following statements is TRUE?
    Question 3
    2024 Slot Set2 PYQ
    Level 3: Exam Standard

    Consider the following augmented grammar, which is to be parsed with a SLR parser. The set of terminals is

    Let . The number of items in the set is __________

    Question 4
    2024 Slot Set1 PYQ
    Level 3: Exam Standard

    Which of the following is/are Bottom-Up Parser(s)?

    Question 5
    2024 Slot Set1 PYQ
    Level 3: Exam Standard
    Consider the operator precedence and associativity rules for the integer arithmetic operators given in the table below.

    Operator Precedence Associativity + Highest Left − High Right * Medium Right / Low Right
    The value of the expression as per the above rules is __________
    Question 6
    2022 PYQ
    Level 3: Exam Standard

    Consider the augmented grammar with as the set of terminals.

    If is the set of two items , then contains exactly __________ items.

    Question 7
    2021 Slot Set2 PYQ
    Level 3: Exam Standard
    Consider the following augmented grammar with as the set of terminals.









    Let . The number of items in the set is __________.
    Question 8
    2021 Slot Set1 PYQ
    Level 3: Exam Standard
    Consider the following statements.

    Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).
    For any context-free grammar, there is a parser that takes at most time to parse a string of length .

    Which one of the following options is correct?
    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.

    Bottom-up and Lr Parsing PYQs for GATE CS

    Solve 8+ Bottom-up and Lr Parsing previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: Bottom-Up and LR Parsing

    Chapter Roadmap: Bottom-Up and LR Parsing

    Building the parse tree from leaves to root: rightmost derivation in reverse.

    Your Learning Journey

    1. Bottom-Up Parser Types and LR Grammar Classes

    The foundation. Understanding handle pruning, rightmost derivations in reverse, and the strict hierarchy of LR(0), SLR(1), LALR(1), and CLR(1) parsers.

    2. Operator Precedence and Shift-Reduce Parsing

    The mechanics. How shift-reduce parsing works in practice, identifying handles, and the specialized rules of operator precedence grammars.

    3. LR Item Closure and GOTO Computation

    The engine. Step-by-step construction of canonical collections of LR items, the CLOSURE operation, and the GOTO function that builds the parsing DFA.

    4. LR Parsing Conflicts and Grammar Ambiguity

    The resolution. Identifying shift-reduce and reduce-reduce conflicts, understanding why they occur, and techniques to resolve them or prove a grammar is not LR.

    Chapter Weightage: High. Expect 1 to 2 questions directly testing LR item construction, conflict identification, or grammar class hierarchy.

    Bottom-Up Parser Types and LR Grammar Classes

    Bottom-Up Parser Types and LR Grammar Classes

    Why this matters: Bottom-up parsing is the most powerful class of deterministic parsing. It forms the basis of almost all automatic parser generators (like YACC and Bison) used in real-world compilers.

    What you will learn here

    • The core concept of "handle pruning" and rightmost derivation in reverse
    • The meaning of the L, R, and k in LR(k) parsing
    • The strict hierarchy of LR grammar classes: LR(0), SLR(1), LALR(1), and CLR(1)
    • How lookahead power trades off with the number of parser states
    Chapter context: Parser Types and LR Classes → Shift-Reduce Mechanics → Item Closure and GOTO → Conflict Resolution

    Bottom-up and Lr Parsing: Solved Questions with Step-by-Step Explanations (8 Problems)

    Question 1 · Compiler Design · 2026_Set2 MCQ
    Consider the canonical parsing of the grammar below using terminals and non-terminals with as the start symbol.





    Which one of the following options gives the number of shift-reduce conflicts that will occur in the ACTION table?
    1. A.

      2

    2. B.

      3

    3. C.

      4

    4. D.

      5

    Correct Answer:

    C

    Step-by-Step Solution

    Insight: Epsilon productions in LR(0) immediately create reduce items in the initial state, which clash with any shift items for the same non-terminal, causing shift-reduce conflicts.

    Exam route: Construct the LR(0) items state by state. Count the exact (state, terminal) pairs where both a shift and a reduce action are valid in the ACTION table.

    Learning route:

    1. State I0: Contains S' -> .S, S -> .ACB, A -> .aA, and A -> . (from ). The dot is before A, not C, so C productions are not yet in I0.
    • A -> . is a reduce item (places reduce in all columns).
    • A -> .aA is a shift item on 'a'.
    • Result: 1 SR conflict (on 'a').
    1. State I1 = GOTO(I0, a): Contains A -> a.A, A -> .aA, A -> ..
    • Shift on 'a', reduce A. Result: 1 SR conflict (on 'a').
    1. State I2 = GOTO(I0, A): Contains S -> A.CB, C -> .cC, C -> ..
    • Shift on 'c', reduce C. Result: 1 SR conflict (on 'c').
    1. State I3 = GOTO(I2, c): Contains C -> c.C, C -> .cC, C -> ..
    • Shift on 'c', reduce C. Result: 1 SR conflict (on 'c').
    1. State I4 = GOTO(I2, C): Contains S -> AC.B, B -> .bB, B -> .b.
    • Only shift items (on 'b'). Result: 0 conflicts.
    1. All other states (like GOTO on S, B) have only reduce items or only shift items, yielding 0 SR conflicts.
    2. Total SR conflicts = 1 + 1 + 1 + 1 = 4.
    Question 2 · Compiler Design · 2025_Set2 MCQ
    Given a Context-Free Grammar as follows:





    Which ONE of the following statements is TRUE?
    1. A.

      is neither LALR(1) nor SLR(1)

    2. B.

      is CLR(1), not LALR(1)

    3. C.

      is LALR(1), not SLR(1)

    4. D.

      is LALR(1), also SLR(1)

    Correct Answer:

    A

    Step-by-Step Solution

    Insight: To determine the parser class, we must check for LR(1) conflicts. If an LR(1) state has a shift-reduce conflict, the grammar is not LR(1), and thus cannot be CLR(1), LALR(1), or SLR(1).

    Exam route: Compute the LR(1) items for the initial state and its GOTO on 'd'. Check if the lookahead for the reduce item intersects with the shift terminal.

    Learning route:

    1. Augmented grammar: S' -> S, S -> Aa | bAc | dc | bda, A -> d.
    2. I0 (LR(1) items):
    • S' -> .S, {$}
    • S -> .Aa, {$}
    • S -> .bAc, {$}
    • S -> .dc, {$}
    • S -> .bda, {$}
    • A -> .d, {a, c} (Lookahead is FOLLOW(A) = {a, c} from S -> Aa and S -> bAc)
    1. Compute GOTO(I0, d):
    • From S -> .dc, we get S -> d.c, {$}
    • From A -> .d, we get A -> d., {a, c}
    1. Analyze GOTO(I0, d) for conflicts:
    • We have a shift action on terminal 'c' (from S -> d.c).
    • We have a reduce action for A -> d on lookaheads {a, c}.
    • Since 'c' is in the lookahead set {a, c}, there is a Shift-Reduce conflict on terminal 'c' in this LR(1) state.
    1. Because there is an unresolvable SR conflict in the canonical LR(1) collection, the grammar is not LR(1).
    2. Consequently, it cannot be CLR(1), LALR(1), or SLR(1). The statement "G is neither LALR(1) nor SLR(1)" is true.
    Question 3 · Compiler Design · 2024_Set2 NAT

    Consider the following augmented grammar, which is to be parsed with a SLR parser. The set of terminals is

    Let . The number of items in the set is __________

    Correct Answer:

    9.00

    Step-by-Step Solution

    Insight: The GOTO operation on a non-terminal shifts the dot past that non-terminal and then computes the closure, which recursively adds productions for any non-terminal immediately following the new dot position.

    Exam route: Identify items in I0 with the dot before S, shift the dot, and then apply the closure rules to count the total items without drawing the full DFA.

    Learning route:

    1. I0 = CLOSURE({S' -> .S}). Since the dot is before S, we add all 5 productions of S. Since the dot is before A and B in some of those, we add their productions. Total items in I0 = 1 (S') + 5 (S) + 1 (A) + 1 (B) = 8.
    2. To find GOTO(I0, S), we filter items in I0 with the dot before S:
    • S' -> .S
    • S -> .SS
    1. Shift the dot past S:
    • S' -> S.
    • S -> S.S
    1. Compute CLOSURE of this new set. The dot is before S in S -> S.S, so we must add all productions of S with the dot at the beginning:
    • S -> .SS
    • S -> .Aa
    • S -> .bAc
    • S -> .Bc
    • S -> .bBa
    1. The dot is now before A in S -> .Aa and before B in S -> .Bc, so we add their productions:
    • A -> .d#
    • B -> .@
    1. Counting all unique items: S' -> S. (1), S -> S.S (1), the 5 S productions (5), A -> .d# (1), B -> .@ (1). Total = 9 items.
    Question 4 · Compiler Design · 2024_Set1 MSQ

    Which of the following is/are Bottom-Up Parser(s)?

    1. A.

      Shift-reduce Parser

    2. B.

      Predictive Parser

    3. C.

      LL(1) Parser

    4. D.

      LR Parser

    Correct Answer:

    ["A","D"]

    Step-by-Step Solution

    Insight: Bottom-up parsers build the parse tree from leaves to root (reduction), while top-down parsers build from root to leaves (derivation).

    Exam route: Classify each parser type based on its direction of tree construction. Shift-reduce and LR are bottom-up. Predictive and LL(1) are top-down.

    Learning route:

    1. Shift-reduce Parser: This is the general mechanical foundation of all bottom-up parsing. It shifts input onto a stack and reduces handles. (Bottom-Up)
    2. Predictive Parser: This is a specific type of recursive descent parser that "predicts" which production to use without backtracking. It builds the tree top-down. (Top-Down)
    3. LL(1) Parser: The 'L' stands for Left-to-right scan, and the second 'L' stands for Leftmost derivation. Leftmost derivation is the hallmark of top-down parsing. (Top-Down)
    4. LR Parser: The 'R' stands for Rightmost derivation in reverse. Reversing a rightmost derivation is exactly the process of bottom-up reduction. (Bottom-Up)
    5. Therefore, Shift-reduce and LR parsers are the correct choices.
    Question 5 · Compiler Design · 2024_Set1 NAT
    Consider the operator precedence and associativity rules for the integer arithmetic operators given in the table below.

    Operator Precedence Associativity + Highest Left − High Right * Medium Right / Low Right
    The value of the expression as per the above rules is __________
    Correct Answer:

    6.00

    Step-by-Step Solution

    Insight: The problem requires evaluating an arithmetic expression using non-standard precedence and associativity rules, simulating an operator precedence parser.

    Exam route: Group the expression step-by-step from highest to lowest precedence, strictly applying the given associativity (Left or Right) at each level.

    Learning route:

    1. Precedence levels: + (Highest, Left), - (High, Right), * (Medium, Right), / (Low, Right).
    2. Group '+' first (Highest, Left-to-Right):
    • 3 + 1 becomes 4.
    • 4 + 5 becomes 9.
    • 7 + 2 becomes 9.

    Expression simplifies to: 9 * 2 / 9 - 4 - 7 - 6 / 2.

    1. Next, group '-' (High, Right-to-Left):
    • Rightmost '-': 7 - 6 becomes 1.
    • Next '-': 4 - 1 becomes 3.
    • Next '-': 9 - 3 becomes 6.

    Expression simplifies to: 9 * 2 / 6 / 2.

    1. Next, group '*' (Medium, Right-to-Left):
    • Only one '': 9 2 becomes 18.

    Expression simplifies to: 18 / 6 / 2.

    1. Lowest, group '/' (Low, Right-to-Left):
    • Rightmost '/': 6 / 2 becomes 3.
    • Next '/': 18 / 3 becomes 6.
    1. Final value is 6.
    Question 6 · Compiler Design · 2022 NAT

    Consider the augmented grammar with as the set of terminals.

    If is the set of two items , then contains exactly __________ items.

    Correct Answer:

    5.00

    Step-by-Step Solution

    Insight: The closure of a set of items where no dot is immediately before a non-terminal is just the set itself. The GOTO operation then shifts the dot past the specified terminal and expands the closure.

    Exam route: Recognize that closure(I0) = I0. Filter for the '+' terminal, shift the dot, and count the resulting closure items.

    Learning route:

    1. Given I0 = {[S' -> S.], [S -> S.+R]}. Neither item has a dot immediately before a non-terminal, so CLOSURE(I0) = I0.
    2. We need GOTO(I0, +). Filter items in I0 with the dot before '+':
    • Only [S -> S . + R] matches.
    1. Shift the dot past '+':
    • [S -> S + . R]
    1. Compute CLOSURE of {[S -> S + . R]}. The dot is immediately before the non-terminal R, so we add all productions of R with the dot at the beginning:
    • [R -> . R * P]
    • [R -> . P]
    1. Now the dot is before P in [R -> . P], so we add all productions of P:
    • [P -> . (S)]
    • [P -> . id]
    1. The dot is before '(' in [P -> . (S)], which is a terminal. So we do NOT add productions of S.
    2. Total items:
    3. S -> S + . R
    4. R -> . R * P
    5. R -> . P
    6. P -> . (S)
    7. P -> . id

    Total = 5 items.

    Question 7 · Compiler Design · 2021_Set2 NAT
    Consider the following augmented grammar with as the set of terminals.









    Let . The number of items in the set is __________.
    Correct Answer:

    8.00

    Step-by-Step Solution

    Insight: The GOTO operation on a terminal simply shifts the dot past that terminal and takes the closure. If the resulting item has a non-terminal after the dot, the closure expands it identically to the previous state.

    Exam route: Compute I0, then GOTO(I0, <), then GOTO of that result on <. Count the items in the final set without drawing the full DFA.

    Learning route:

    1. Compute I0 = CLOSURE({S' -> .S}). Since the dot is before S, we add all 7 productions of S with the dot at the beginning. Total items in I0 = 1 (augmented) + 7 = 8.
    2. Compute GOTO(I0, <). We look for items in I0 with the dot before '<'. Only S -> .<S> matches. Shifting the dot gives S -> <.S>.
    3. Compute CLOSURE({S -> <.S>}). The dot is before S, so we add all 7 productions of S with the dot at the beginning. This results in exactly the same 8 items as I0, but with S -> <.S> instead of S' -> .S. Let's call this I1. Total items = 8.
    4. Compute GOTO(I1, <). Again, only S -> .<S> has the dot before '<'. Shifting gives S -> <.S>, and its closure is identical to I1.
    5. The number of items in this set is 8.
    Question 8 · Compiler Design · 2021_Set1 MCQ
    Consider the following statements.

    Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).
    For any context-free grammar, there is a parser that takes at most time to parse a string of length .

    Which one of the following options is correct?
    1. A.

      is true and is false

    2. B.

      is false and is true

    3. C.

      is true and is true

    4. D.

      is false and is false

    Correct Answer:

    C

    Step-by-Step Solution

    Insight: SLR(1) is a strict subset of unambiguous grammars, and the CYK/Earley algorithms guarantee parsing time for any context-free grammar.

    Exam route: Evaluate S1: All LR(k) grammars are unambiguous, but not all unambiguous grammars are SLR(1) (e.g., some require LALR(1) or CLR(1) lookahead). Evaluate S2: CYK algorithm parses any CFG in . Both statements are fundamental theorems.

    Learning route:

    1. Statement S1: "Every SLR(1) grammar is unambiguous" is TRUE. If a grammar is ambiguous, it generates multiple parse trees, making deterministic LR parsing impossible. "There are certain unambiguous grammars that are not SLR(1)" is also TRUE. For example, some grammars are LR(1) but not SLR(1) due to FOLLOW set overlaps, yet they remain perfectly unambiguous.
    2. Statement S2: "For any context-free grammar, there is a parser that takes at most time" is TRUE. The Cocke-Younger-Kasami (CYK) algorithm can parse any CFG (after conversion to Chomsky Normal Form) in time. Earley's algorithm also achieves for any CFG.
    3. Conclusion: Both S1 and S2 are true.

    More previous year questions (pyqs) in this unit