in Compiler Design retagged by
12,334 views
19 votes
19 votes

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 ___________.

in Compiler Design retagged by
by
12.3k views

2 Comments

| Stack   | Input | Action           |
| ------- | ----- | ---------------- |
| $aaad   | bbb$  |                  |
| $aaaS   | bbb$  | reduction S->d   |
| $aaaSb  | bb$   | reduction B->b   |
| $aaaSB  | bb$   | reduction S->aSB |
| $aaSb   | b$    | reduction B->b   |
| $aaSB   | b$    | reduction S->aSB |
| $aSb    | $     | reduction B->b   |
| $S      | $     | reduction S->aSB |

Note : Skipped shift steps. 
2
2
Nice question
0
0

2 Answers

33 votes
33 votes
Best answer

In parse tree, all the non terminals are reductions. So total 7 reductions.

edited by

3 Comments

Can’t we take the string and try to reach to the initial symbol? That is how bottom up works right?
0
0
Yes, you can use that approach as well.
0
0
can we think of the idea from Gribeck Normal form
0
0
28 votes
28 votes
Given string : aaadbbb

 

Bottom-up parsers : rightmost derivation in reverse.

S -> aSB

S -> aSb

S -> aaSBb

S -> aaSbb

S -> aaaSBbb

S -> aaaSbbb

S -> aaadbbb

So, there are 7 steps.
Answer:

Related questions