Consider the following grammar. \(S \rightarrow aSB \mid d\) \(B \rightarrow…

2020

Consider the following grammar.

\(S \rightarrow aSB \mid d\)

\(B \rightarrow b\)

The number of reduction steps taken by a bottom-up parser while accepting the string \(aaadbbb\) is ________ .

Answer: 7Answer: 7 reduction steps. Why: Each reduction in a bottom-up parser corresponds to applying one grammar production in reverse. To generate the string aaadbbb…

Attempted by 142 students.

Show answer & explanation

Correct answer: 7

Answer: 7 reduction steps.

Why:

Each reduction in a bottom-up parser corresponds to applying one grammar production in reverse. To generate the string aaadbbb the grammar uses S → aSB three times, S → d once, and B → b three times, so the total number of productions (reductions) is 3 + 1 + 3 = 7.

A possible bottom-up reduction sequence (showing the substring reduced each time):

  • aaadbbb → aaadbbB (reduce b → B) — 1

  • aaadbbB → aaadbBB (reduce b → B) — 2

  • aaadbBB → aaadBBB (reduce b → B) — 3

  • aaadBBB → aaaSBBB (reduce d → S) — 4

  • aaaSBBB → aaSBB (reduce a S B → S) — 5

  • aaSBB → aS B (reduce a S B → S) — 6

  • aSB → S (reduce a S B → S) — 7 (accept)

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…