Parser Types
Understanding SLR, LALR, and LR(1) parsers in Galore
Parser Types
Galore supports three types of bottom-up parsers. Each has different trade-offs between power and complexity.
SLR (Simple LR)
The simplest LR parser. Uses FOLLOW sets to resolve conflicts.
- Smallest parse tables
- Fastest to construct
- Can handle fewer grammars than LALR or LR(1)
const parser = G.newParser(grammar, { type: "slr" });
LALR (Look-Ahead LR)
The most commonly used parser type. Balances power and efficiency.
- Same table size as SLR
- More powerful than SLR
- Used by tools like Yacc and Bison
const parser = G.newParser(grammar, { type: "lalr" });
LR(1) (Canonical LR)
The most powerful LR parser. Uses full lookahead information.
- Largest parse tables
- Can handle all deterministic context-free grammars
- More memory intensive
const parser = G.newParser(grammar, { type: "lr1" });
Comparison
| Parser Type | Table Size | Power | Use Case |
|---|---|---|---|
| SLR | Small | Limited | Simple grammars |
| LALR | Small | Good | Most programming languages |
| LR(1) | Large | Full | Complex grammars |