SLR(1) Grammars
1. Idea
SLR(1) = Simple LR with 1 lookahead: reuse the LR(0) item sets, but reduce A → α only when lookahead is in FOLLOW(A). Cheap fix that resolves many LR(0) conflicts.
2. SLR Table Construction
1. build canonical LR(0) collection (states + goto)
2. action[i,a]: shift j if goto(i,a)=j (a terminal)
3. action[i,a]: reduce A→α for every a in FOLLOW(A) if state i has A→α•
4. goto[i,A] for non-terminals; accept on S'→S• + $
One state → one row; FOLLOW decides reduces.
3. Example Conflict Resolved
E → E+T | T (I with E→T• and T→T•id?) — classic SLR case:
state {E→T•, T→T•*F}: shift on *, reduce E→T on +,$,) — disjoint because * ∉ FOLLOW(E)
→ SLR succeeds where LR(0) had shift-reduce conflict
Fails when FOLLOW overlap remains, e.g. S → L=R | R, L → *R | id, R → L: state with R→L• and L→L•=R? FOLLOW overlap on = → not SLR (needs LR(1)).
4. Power Position
LL(1) ⊂ SLR(1) ⊂ LALR(1) ⊂ LR(1). SLR handles most expressions, lists, matched brackets; needs only small tables.
5. Exam Points
- Build SLR(1) table from LR(0) sets + FOLLOW — 7-10 marks, very frequent.
- Distinguish LR(0) vs SLR(1) (FOLLOW-based reduce) — 3-5 marks, frequent.
- Show a grammar that is not SLR (FOLLOW conflict) — 5 marks, frequent.