Consider the context-free grammar with start symbol , non-terminals and terminals :
Which ONE of the following statements is TRUE?
Show solution
Solution MCQ · 2 marks · −⅔ if wrong
Answer: (B) G is LALR(1) but not SLR(1)
Method. Build only the states that can conflict, then test with FOLLOW (SLR) and with LR(1) lookaheads (CLR/LALR).
Augment with . The LR(0) state contains , , , , . On :
Two complete items in one state: a reduce-reduce conflict unless the lookaheads separate them.
SLR(1). (from and ), . On the parser could reduce by either rule: conflict, so not SLR(1).
CLR(1). In the LR(1) start state the items are and , so is , : no conflict. After , the item is and its -successor is , alone in its state. No other state has a conflict, so is CLR(1).
LALR(1). LALR merges states with the same LR(0) core. The core and the core are different, so nothing merges and the LALR table equals the CLR table: LALR(1).
The trap. SLR uses the whole FOLLOW set of a non-terminal, which mixes contexts: follows only after , never in the state reached directly on . Seeing "two states with " and concluding LALR will merge them is the opposite slip; merging needs identical item cores, not one shared item.
What was tested. Why LR(1) lookaheads are finer than FOLLOW sets, and exactly when LALR merging happens, applied to the containment SLR(1) LALR(1) CLR(1).
Copied. Paste it into the new chat.Too long to send. Copy the question and solution by hand.