Unit-1compiler design
Unit-1compiler design
Unit – 1
Pushdown
Introduction to Compiler
Automata
Compiler Design
Unit – 1 : Introduction to Compiler 1 Darshan Institute of Engineering & Technology
Topics to be covered
Translator
Analysis synthesis model of compilation
Phases of compiler
Difference between compiler & interpreter
Types of compiler
Context of compiler (Cousins of compiler)
Pass structure
Error
Messages (If any)
Unit – 1 : Introduction to Compiler 4 Darshan Institute of Engineering & Technology
Compiler
A compiler is a program that reads a program written in source
language and translates it into an equivalent program in target
language.
Lexical analysis
Intermediate Code
code optimization
Syntax analysis generation
Code
Semantic analysis generation
Lexical analysis
Intermediate Code
code optimization
Syntax analysis generation
Code
Semantic analysis generation
id1 +
id2 *
id3 60
Lexical analysis
Intermediate Code
code optimization
Syntax analysis generation
Code
Semantic analysis generation
*Note: Consider id1, id2 and id3 are real id3 inttoreal
60
Unit – 1 : Introduction to Compiler 17 Darshan Institute of Engineering & Technology
Phases of compiler
Compiler
Lexical analysis
Intermediate Code
code optimization
Syntax analysis generation
Code
Semantic analysis generation
Lexical analysis
Intermediate Code
code optimization
Syntax analysis generation
Code
Semantic analysis generation
Code optimization
Lexical analysis
Intermediate Code
code optimization
Syntax analysis generation
Code
Semantic analysis generation
Code generation
MOVF id3, R2
MULF #60.0, R2
MOVF id2, R1
ADDF R2,R1
MOVF R1, id1
Analysis Phase
Lexical analysis
Syntax analysis
Semantic analysis
Symbol table Error detection
and recovery
Intermediate code
Preprocessor
It performs the following functions:
1. Macro processing
2. File inclusion
3. Rational preprocessor
4. Language extensions
Preprocessor
1. Macro processing: Allows user to define macros. Macro is shorthand
for longer constructs.
Ex: #define PI 3.14159265358979323846
2. File inclusion: A preprocessor may include the header file into the
program.
Ex: #include<stdio.h>
3. Rational preprocessor: It provides built in macro for construct like
while statement or if statement.
Preprocessor
4. Language extensions: Add capabilities to the language by using
built-in macros.
• Ex: the language equal is a database query language
embedded in C.
• Statement beginning with ## are taken by preprocessor to be
database access statement unrelated to C and translated into
procedure call on routines that perform the database access.
Compiler
• A compiler is a program that reads a program written in source
language and translates it into an equivalent program in target
language.
Assembler
• Assembler is a translator which takes the assembly program
(mnemonic) as an input and generates the machine code as an
output.