GateAI
Lexical Analysis, Parsing and SDT

GATE CSE 2020 · Q24

NAT1 markMedium

Time

Consider the following grammar. S→aSB∣dS \rightarrow aSB \mid d B→bB \rightarrow b The number of reduction steps taken by a bottom-up parser while accepting the string aaadbbbaaadbbb is _______.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 7

Lexical Analysis, Parsing and SDT

A bottom-up parser traces the rightmost derivation in reverse to reduce the input string to the start symbol SS.

Let us construct the rightmost derivation of the string aaadbbbaaadbbb from SS:

  1. S⇒aSBS \Rightarrow aSB

  2. ⇒aSb\Rightarrow aSb (using B→bB \rightarrow b)

  3. ⇒a(aSB)b=aaSBb\Rightarrow a(aSB)b = aaSBb (using S→aSBS \rightarrow aSB)

  4. ⇒aaSbb\Rightarrow aaSbb (using B→bB \rightarrow b)

  5. ⇒aa(aSB)bb=aaaSBbb\Rightarrow aa(aSB)bb = aaaS Bbb (using S→aSBS \rightarrow aSB)

  6. ⇒aaaSbbb\Rightarrow aaaSbbb (using B→bB \rightarrow b)

  7. ⇒aaa(d)bbb=aaadbbb\Rightarrow aaa(d)bbb = aaadbbb (using S→dS \rightarrow d)

The bottom-up parser performs these 7 derivation steps in reverse order as reductions:

  • Step 1: d→Sd \rightarrow S, reducing aaadbbbaaadbbb to aaaSbbbaaaSbbb

  • Step 2: b→Bb \rightarrow B, reducing aaaSbbbaaaSbbb to aaaSBbbaaaSBbb

  • Step 3: aSB→SaSB \rightarrow S, reducing aaaSBbbaaaSBbb to aaSbbaaSbb

  • Step 4: b→Bb \rightarrow B, reducing aaSbbaaSbb to aaSBbaaSBb

  • Step 5: aSB→SaSB \rightarrow S, reducing aaSBbaaSBb to aSbaSb

  • Step 6: b→Bb \rightarrow B, reducing aSbaSb to aSBaSB

  • Step 7: aSB→SaSB \rightarrow S, reducing aSBaSB to SS

Total number of reduction steps is 7.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Lexical Analysis, Parsing and SDT previous year question is Q24 of the GATE CSE 2020 paper. Find more GATE CSE PYQs on Lexical Analysis, Parsing and SDT in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Lexical Analysis, Parsing and SDT PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Lexical Analysis, Parsing and SDT in GATE CSE

Lexical Analysis, Parsing and SDT has 14 GATE CSE PYQs across 12 papers from 2011 to 2025. 2 of them are 1-mark NAT questions like this one, and it is the only one in GATE CSE 2020.

How GATE tests Lexical Analysis, Parsing and SDT

More from GATE CSE 2020

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2020 · Q24 · NAT

Consider the following grammar. S → aSB d B → b The number of reduction steps taken by a bottom-up parser while accepting the string aaadbbb is …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.