Parsing & Syntax Analysis


Answer & solution
Official answer: 7
Step through it (16 steps)
Worked explanation
An explicit reduction sequence is aaadbbb ⇒ aaaSbbb ⇒ aaaSBbb ⇒ aaSbb ⇒ aaSBb ⇒ aSb ⇒ aSB ⇒ S. The first step uses d→S; each pair thereafter uses b→B followed by aSB→S. Thus there are 1+3+3=7 reductions. The corresponding derivation tree has four S-production nodes and three B-production nodes. A bottom-up parser may also shift seven terminals and eventually perform an accept action; neither shifts nor accept are additional grammar reductions.
Derivation and answer
The derivation uses S→aSB three times, S→d once, and B→b three times. A bottom-up parse reverses these seven production applications, so it performs 7 reductions, excluding the separate parser accept action.