(in simple language with definitions, working, items, tables, examples, diagrams, and key exam points)
LR Parsing is a bottom-up parsing technique that reads input:
👉 So LR means:
“Scan input left-to-right and produce rightmost derivation in reverse.”
LR parser builds the parse tree: 👉 from bottom (input) to top (start symbol)
✔ Most powerful deterministic parsing method ✔ Used in real compilers ✔ Handles large class of grammars ✔ No backtracking
| Type | Meaning |
|---|---|
| LR(0) | Simplest LR parser |
| SLR(1) | Simple LR with FOLLOW sets |
| CLR(1) | Canonical LR (most powerful) |
| LALR(1) | Look-Ahead LR (used in practice) |
An LR(0) parser is a bottom-up parser that uses:
An LR(0) item is a production with a dot (•) showing parsing position.
E → E + T
E → T
T → id
E → E + T
Items:
E → • E + T
E → E • + T
E → E + • T
E → E + T •
👉 Dot shows how much of production is parsed
Closure adds all possible productions for a non-terminal after dot.
If:
A → α • B β
Then add:
GOTO moves the dot over a symbol.
If:
E → E • + T
After GOTO(+):
E → E + • T
LR(0) parser uses a DFA:
States (Items) → Transitions → Parsing Table
Two parts:
| Part | Meaning |
|---|---|
| ACTION | shift/reduce/accept |
| GOTO | next state |
E → E + T | T
T → id
E' → E
States are built using:
| State | id | + | $ | E | T |
|---|---|---|---|---|---|
| 0 | S5 | 1 | 2 | ||
| 1 | S6 | ACC | |||
| 2 | R2 | R2 | |||
| 5 | R3 | R3 |
Legend:
Start with initial state (0)
Read input left to right
Use ACTION table:
Use GOTO for transitions
Accept when input is fully parsed
❌ Too weak ❌ Cannot handle many grammars ❌ Shift-reduce conflicts common ❌ No lookahead (big issue)
| Feature | LR(0) | SLR(1) | CLR(1) |
|---|---|---|---|
| Lookahead | None | 1 | 1 |
| Power | Weak | Medium | Very Strong |
| Conflicts | Many | Fewer | Almost none |
| Use | Theory | Some use | Compiler design |
👉 Frequently asked:
| Aspect | LR Parsing | LR(0) Parser |
|---|---|---|
| Definition | Parsing technique | Simplest LR parser |
| Direction | Bottom-up | Bottom-up |
| Lookahead | Depends on type | None |
| Method | LR family | LR(0) items |
| Strength | Very powerful | Weak |
| Components | Stack, table | Items, DFA |
| Use | Compiler design | Theoretical basis |
Open this section to load past papers