SLR, Non SLR and LR(1) grammar ● SLR grammar ● A grammar is said to be an SLR grammar if the SLR parsing table for the grammar has no conflicting entries
SLR, Non SLR and LR(1) grammar ● A → B +. C A → B. + C A → B. + SiSi SjSj
SLR, Non SLR and LR(1) grammar ● LR(1) grammar If the current state is S i and + is the next token, a shift is made leading to the state Sj Reduction cannot be made because the lookahead symbol * and the next token + does not match A → B +. C A → B. + C, = A → B., * + SiSi SjSj
LR(1) vs SLR parser ● LR(1) parser is better than SLR parser because LR(1) accepts more languages than SLR ● SLR(1) is weak because it has no lookahead information ● But the cost is LR(1) has more states than SLR and thus it consumes more space ● LR(1) is impractical because its lookahead information makes the automaton too big
Can we retain the LR(1) automaton's lookahead information without all its states?
Review of LR(1) ● Each state in an LR(1) automaton is a combination of an LR(0) state and lookahead information. ● Two LR(1) items have the same core if they are identical except for lookahead.
A Surprisingly Powerful Idea ● In an LR(1) automaton, we have multiple states with the same core but different Lookahead ● What if we merge all these states together? This is called LALR parser Lookahead LR parser