Compiler_Design_Notes
Compiler_Design_Notes
- Tokenizes input
- Removes whitespace/comments
- Passes tokens to parser
**Input Buffering:** Technique for efficient scanning using buffers with sentinel characters.
**Lexical Analyzer Generator (LEX):** Tool that generates lexical analyzers. Example:
DIGIT [0-9]
%%
{DIGIT}+ { printf("Number"); }
%%
**Regular Expressions and Finite Automata:** REs define languages recognized by FA.
**Design of Lexical Analyzer Generator:** Converts REs to NFA -> DFA -> minimized DFA ->
code.
**Derivations and Parse Trees:** Show how strings derive from grammar. Leftmost and
rightmost derivations.
**Ambiguity:** A grammar with multiple parse trees for the same string.
**Left Recursion:** Grammar with productions like A -> Aα. Must be removed for top-down
parsing.
---
**Recursive Descent Parsing:** Uses mutually recursive functions for grammar rules.
**Error Recovery in Predictive Parsing:** Techniques include panic mode and phrase-level
recovery.
**Difference between LR and LL Parsers:** LR parsers are more powerful and can handle
left recursion.
**Shift-Reduce Parsing:** Uses stack and input buffer. Shift moves input to stack; reduce
applies grammar.
**SLR Table Construction:** Compute FIRST, FOLLOW, item sets, ACTION/GOTO tables.
**CLR and LALR Parsers:** More powerful, use lookahead. LALR combines similar CLR
states.
**Dangling Else Ambiguity:** "else" may match multiple "if"s. Resolved via grammar.
---
**Evaluation Orders for SDDs:** Post-order traversal for bottom-up; pre-order for top-
down.
t1 = a + b
t2 = t1 * c
---
---
**Register Allocation and Assignment:** Efficient use of CPU registers using graph coloring.
---
**Note:** Each unit's examples and key diagrams (like DFA for token recognition, parse
trees, TAC examples) should be practiced separately.
These notes aim to summarize core compiler design concepts with clarity.