(Exam-ready, simple explanation with steps, diagrams, and examples)
An SLR(1) (Simple LR) parser is a bottom-up parser that uses:
👉 Full form:
Simple LR (1 lookahead via FOLLOW sets)
SLR(1) = LR(0) automaton + FOLLOW sets to resolve reduce decisions.
LR(0) has problems: ❌ Too many shift-reduce conflicts ❌ No lookahead information
👉 SLR fixes this using: ✔ FOLLOW sets ✔ Better reduce decisions
Add new start symbol:
S' → S
Create items using:
👉 This forms LR(0) automaton
Used for reduce decisions
Fill ACTION and GOTO tables
S → CC
C → cC | d
S' → S
S → CC
C → cC | d
FOLLOW(S) = { $ }
FOLLOW(C) = { c, d, $ }
If:
A → α • a β
Then:
ACTION[i, a] = SHIFT j
If:
A → α •
Then:
ACTION[i, a] = REDUCE A → α
for all a ∈ FOLLOW(A)
👉 This is the main difference from LR(0)
If:
S' → S •
Then:
ACTION[i, $] = ACCEPT
If:
GOTO(I, A) = j
Then:
GOTO[i, A] = j
States are built using:
👉 Example transitions:
I0 --c--> I1
I0 --d--> I2
I0 --C--> I3
| State | c | d | $ | S | C |
|---|---|---|---|---|---|
| 0 | S1 | S2 | 3 | 4 | |
| 1 | S1 | S2 | 5 | ||
| 2 | R C→d | R C→d | R C→d | ||
| 3 | ACC |
Legend:
Push state 0 on stack
Read input
Use ACTION table:
Use GOTO for transitions
✔ Simple to construct ✔ Uses LR(0) automaton ✔ More powerful than LR(0) ✔ Reduces many conflicts
❌ Still has conflicts in complex grammars ❌ Not as powerful as CLR(1) ❌ Uses FOLLOW sets → sometimes too broad
| Feature | LR(0) | SLR(1) |
|---|---|---|
| Lookahead | None | FOLLOW set |
| Conflicts | Many | Reduced |
| Power | Weak | Medium |
| Table | Simple | Better |
| Use | Theory | Basic parsing |
👉 Very frequently asked:
| Aspect | SLR(1) Parser |
|---|---|
| Full form | Simple LR (1) |
| Type | Bottom-up |
| Basis | LR(0) + FOLLOW |
| Lookahead | 1 (indirect) |
| Strength | Medium |
| Tables | ACTION + GOTO |
| Conflicts | Reduced vs LR(0) |
| Use | Syntax analysis |
Open this section to load past papers