You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/architecture.md
+57-1Lines changed: 57 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -214,7 +214,63 @@ The parser uses **recursive descent parsing** - a method where each grammar rule
214
214
-`comparison()` handles comparison operations
215
215
-`unary()` handles unary operators like `++` and `--`
216
216
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.
- 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.
0 commit comments