Esp (CD)
Esp (CD)
What is a Compiler?
• A compiler is a program that translates high-level source code written by a programmer into
machine code that a computer can execute.
Phases of a Compiler
1. Analysis Phase
• Lexical Analysis:
o Tools: Lex.
o Tools: Yacc.
• Semantic Analysis:
2. Synthesis Phase
o Example: x = y + z → T1 = y + z, x = T1.
• Code Optimization:
• Code Generation:
Types of Parsers
1. Top-Down Parsing:
2. Bottom-Up Parsing:
ey Concepts
1. Lexeme
• The smallest sequence of characters in the source code that matches a token.
2. Token
3. Regular Expression
4. Symbol Table
• A data structure storing information about variables, functions, and objects in the program.
5. Predictive Parsing
6. LR Parsing
1. Lexical Errors:
2. Syntax Errors:
3. Semantic Errors:
4. Runtime Errors:
Advantages of Compilers
2. Chomsky Hierarchy
• FIRST: The set of terminals that can appear as the first symbol of a string derived from a non-
terminal.
• FOLLOW: The set of terminals that can appear immediately after a non-terminal.
4. Peephole Optimization
• A local optimization technique that works on a small part of the code (a "peephole").