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: $n_1 < n_2 < n_3$ $n_1 = n_3 < n_2$ $n_1 = n_2 = n_3$ $n_1 \geq n_3 \geq n_2$ Compiler Design gatecse-2005 compiler-design parsing normal + – Kathleen asked Sep 22, 2014 Kathleen 15.3k views answer comment Share Follow See 1 comment See all 1 1 comment reply Nitesh Singh 2 commented Jan 19, 2019 reply Follow Share no need to construct table just see the answer if it is unique standard relation then it is the answer. If not then make parsing diagram for CLR only because other will be same and extra state made in CLR then option B other wise option C 1 votes 1 votes Please log in or register to add a comment.
Best answer 38 votes 38 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/ Aditi Dan answered Dec 22, 2014 edited Nov 20, 2022 by Arjun Aditi Dan comment Share Follow See all 17 Comments See all 17 17 Comments reply Show 14 previous comments KUSHAGRA गुप्ता commented Nov 2, 2019 i edited by KUSHAGRA गुप्ता Nov 2, 2019 reply Follow Share @Aditi Dan @pC @rajan Both in SLR(1) and LALR(1), states are the LR(0) items I think for LALR(1) it's is LR(1) Items only Even here also it's written same https://gateoverflow.in/478/gate2008-55 2 votes 2 votes abir_banerjee commented Oct 22, 2022 reply Follow Share @Lakshman Patel RJIT please edit the answer because only SLR(1) is collection of LR(0) items and LR(1) and LALR(1) are collection of LR(1) items. 1 votes 1 votes Arjun commented Nov 20, 2022 reply Follow Share @abir_banerjee That's not exactly true. Please see the answer now. 0 votes 0 votes Please log in or register to add a comment.
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 sujaygoswami answered Dec 29, 2021 sujaygoswami comment Share Follow See all 0 reply Please log in or register to add a comment.