I can't seem to understand the difference between LALR(1) and LR(1) except that LALR(1) seems to have fewer states than LR(1) does.
I wonder if anyone has the example to show the difference and some explanation.
Thank you
There's an example in the Dragon book (Example 4.44; 4.58 if you have the second edition):
S' → S
S → aAd | bBd | aBe | bAe
A → c
B → c
Since the grammar only generates four strings, it's easy enough to create the LR item sets. When you do that, you'll see that there are two sets with the same items but different lookaheads, corresponding to the prefixes ac and bc. There are no conflicts, so the grammar is LR(1).
The LALR algorithm combines states whose items sets are the same, effectively merging their lookaheads. This creates a reduce/reduce conflict, so the grammar is not LALR(1).
S -> aAd | aBe? If not, why not? 2. Could you elaborate more on what "item sets" and "kernel" mean?S -> aAd | aBe, and the newly simplified grammar would still work with LR(1) but not LALR(1)