edited by
35,775 views
83 votes
83 votes

What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon and unit-production (i.e., of type $A \rightarrow \epsilon$ and $A \rightarrow a$) to parse a string with $n$ tokens?

  1. $n/2$
  2. $n-1$
  3. $2n-1$
  4. $2^{n}$
edited by

13 Answers

Best answer
84 votes
84 votes

Ans will be B

  • $A \rightarrow BC$
  • $B \rightarrow aa$
  • $C \rightarrow bb$

Now suppose string is $aabb.$ Then

$A \rightarrow BC$ (reduction $3$)
$\quad \rightarrow aaC$ (reduction $2$)
$\quad \rightarrow aabb$ (reduction $1$)

$n = 4$ and number of reductions is $3.$ So, $n-1$

edited by
33 votes
33 votes

Answer B option.

To get maximum number of Reduce moves, we should make sure than in each sentential form only one terminal is reduced. Since there is no unit production, so last 2 tokens will take only 1 move.

So To Reduce input string of n tokens, first Reduce n-2 tokens using n-2 reduce moves and then Reduce last 2 tokens using production which has . So total of n-2+1 = n-1 Reduce moves.


Example for this could be :

S-->aA

A-->bB

B-->cC

C->de


Generate string of 5 tokens as

S-->aA

  -->abB

  -->abcC

  -->abcde

So first we take 3 steps to reduce ' abc ' and then take 1 step to produce ' de '. So total (5-2) + 1 = 4 Reduction moves

6 votes
6 votes
The answer is C.

Take,

S-->AB

A-->a

B-->b.

Derive ab. you'll have 3 reduce moves.
2 votes
2 votes
Input length = n;

From backward 1st level reduce move = n/2;

2nd level reduce move = n/4;

3rd level reduce move = n/8;

and so on....

so total no of reduce move: n/2+n/4+n/8+n/18+......+1

which is equal to ~=n-1
Answer:

Related questions

13.5k
views
4 answers
53 votes
Arjun asked Sep 24, 2014
13,549 views
Consider the following two sets of $\textsf{LR(1)}$ items of an $\textsf{LR(1)}$ grammar.$\begin{array}{l|l}X \rightarrow c.X, c∕d &X → c.X, \$\\X \rightarrow .cX, c∕ d& X → ... $2$ only $1$ and $4$ only $\text{1, 2, 3}$ and $4$
7.1k
views
3 answers
16 votes
go_editor asked Apr 21, 2016
7,139 views
The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have atmost two ... memory? Do not apply any optimization other than optimizing register allocation.3456
29.1k
views
5 answers
36 votes
Arjun asked Sep 24, 2014
29,098 views
The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have atmost two source operands and ... is the minimum number of spills to memory in the compiled code?0123
8.8k
views
2 answers
29 votes
go_editor asked Feb 14, 2015
8,761 views
Among simple LR (SLR), canonical LR, and look-ahead LR (LALR), which of the following pairs identify the method that is very easy to implement and ... powerful, in that order?SLR, LALRCanonical LR, LALRSLR, canonical LRLALR, canonical LR