Fundamentals
How Parsing Actually Thinks
Before diving into formal grammar and algorithms, you must understand the two fundamentally different ways to approach parsing.
Why This Page Exists
This is the #1 confusion-clearer for parsing students. Textbooks often jump straight into FIRST/FOLLOW sets and DFA states. But every parser is just answering one of two questions:
Top-Down: "Which rule should I predict?"
Bottom-Up: "When should I reduce this back to a rule?"
Top-Down Thinking
Start from Start Symbol S, predict productions, generate the string.
S → A B
A → a
B → b
Press Next to start
Bottom-Up Thinking
Input: 'ab', reduce backwards to S.
S → A B
A → a
B → b
Press Next to start
|
Top-Down |
Bottom-Up |
| Starts from |
Start symbol S |
Input tokens |
| Strategy |
Predict & expand |
Shift & reduce |
| Key Question |
Which production to apply next? |
When to reduce the stack? |
| Parsers |
LL(1), Recursive Descent |
LR(0), SLR, CLR, LALR |
| Direction |
Left→Right, builds downward |
Left→Right, builds upward |
The Key Insight
Every parser you will learn is just a systematic way of answering ONE question: which rule to apply, and when.