15,768 views
24 votes
24 votes

Consider the grammar:

$$S \rightarrow (S) \mid a$$

Let the number of states in SLR (1), LR(1) and LALR(1) parsers for the grammar be $n_1, n_2$ and $n_3$ respectively. The following relationship holds good:

  1. $n_1 < n_2 < n_3$
  2. $n_1 = n_3 < n_2$
  3. $n_1 = n_2 = n_3$
  4. $n_1 \geq n_3 \geq n_2$

2 Answers

Best answer
39 votes
39 votes

ans B

Both in SLR(1) and LALR(1), states are the LR(0) items (LALR uses LR(1) items to form the states but then merges the ones having same items and different lookaheads) while in LR(1) the states are LR(1) set of items. Number of LR(0) items can never be greater than number of LR(1) items. So, $n_1 = n_3 \leq n_2$, B choice.  If we construct the states for the grammar we can replace $\leq$ with $<$.

Reference: https://gatecse.in/lr-parsing-part-4-slr-clr-lalr-and-summary/

edited by
1 votes
1 votes
LALR(1) is formed by merging states of LR(1) ( also called CLR(1)), hence no of states in LALR(1) is less than no of states in LR(1), therefore n3 < n2. And SLR(1) and LALR(1) have same no of states, i.e ( n1 = n3).

Hence n1 = n3 < n2
Answer:

Related questions

11.8k
views
2 answers
31 votes
go_editor asked Nov 27, 2016
11,813 views
Consider the following expression grammar. The semantic rules for expression evaluation are stated next to each grammar production.$$\begin{array}{l|l} E\rightarrow numbe...
20.9k
views
7 answers
56 votes
Kathleen asked Sep 22, 2014
20,895 views
Statement for Linked Answer Questions 83a & 83b:Consider the following expression grammar. The semantic rules for expression evaluation are stated next to each grammar pr...
24.0k
views
4 answers
37 votes
Kathleen asked Sep 22, 2014
24,011 views
The grammar $A \rightarrow AA \mid (A) \mid \epsilon$ is not suitable for predictive-parsing because the grammar is:ambiguousleft-recursiveright-recursivean operator-gram...
22.3k
views
9 answers
81 votes
Vikrant Singh asked Nov 12, 2014
22,298 views
Consider line number $3$ of the following C-program.int main() { /*Line 1 */ int I, N; /*Line 2 */ fro (I=0, I<N, I++); /*Line 3 */ }Identify the compiler’s response ab...