Skip to content

Commit 092733b

Browse files
authored
Update architecture.md
1 parent 59a4b21 commit 092733b

1 file changed

Lines changed: 57 additions & 1 deletion

File tree

docs/architecture.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,63 @@ The parser uses **recursive descent parsing** - a method where each grammar rule
214214
- `comparison()` handles comparison operations
215215
- `unary()` handles unary operators like `++` and `--`
216216

217-
Parser duties:
217+
###### Parsing Techniques
218+
219+
**1. Top-Down Parsing**
220+
221+
This approach constructs the parse tree starting from the **root (start symbol)** and moves toward the **leaves (input tokens)** using **leftmost derivation**.
222+
223+
**a) Recursive Descent Parsing**
224+
- A simple and intuitive parsing method.
225+
- Each non-terminal in the grammar is associated with a separate procedure/function.
226+
- Often uses **backtracking**, meaning it tries alternative productions if one fails.
227+
- Drawbacks:
228+
- Can be inefficient due to backtracking.
229+
- Cannot handle **left-recursive grammars** directly.
230+
231+
**b) Predictive Parsing (LL Parsing)**
232+
- A non-recursive top-down parsing technique.
233+
- Uses a **parsing table** and **look-ahead tokens** to choose the correct production rule.
234+
- Does **not** require backtracking, making it more efficient.
235+
- Requirements:
236+
- Grammar must be free of **left recursion**.
237+
- Grammar should not have **common prefixes** (usually removed using left factoring).
238+
239+
---
240+
241+
**2. Bottom-Up Parsing**
242+
243+
This approach constructs the parse tree starting from the **leaves (input tokens)** and moves toward the **root (start symbol)**, effectively performing a **reverse rightmost derivation**.
244+
245+
**a) Shift-Reduce Parsing**
246+
- Fundamental bottom-up parsing mechanism.
247+
- Two main operations:
248+
- **Shift:** Push the next input symbol onto the stack.
249+
- **Reduce:** Replace a handle on the stack with the corresponding non-terminal using grammar rules.
250+
- Repeats these operations until the start symbol is obtained.
251+
252+
**b) LR Parsing**
253+
- A powerful family of bottom-up parsers.
254+
- Types include:
255+
- LR(0)
256+
- SLR(1)
257+
- LALR(1)
258+
- CLR(1) / Canonical LR(1)
259+
- Features:
260+
- Deterministic parsing.
261+
- No backtracking required.
262+
- Can handle a larger class of grammars than top-down parsers.
263+
- Widely used in compiler construction.
264+
265+
**c) Operator Precedence Parsing**
266+
- A specialized bottom-up parsing technique.
267+
- Primarily used for parsing arithmetic expressions.
268+
- Uses:
269+
- **Operator precedence** (e.g., `*` before `+`)
270+
- **Associativity** (left-to-right or right-to-left)
271+
- Simplifies expression parsing without requiring a full LR parser.
272+
273+
**Parser duties:**
218274
- Validates syntax
219275
- Builds the AST
220276
- Tracks variable declarations (symbols)

0 commit comments

Comments
 (0)