Unit 1 - Overview of The Compiler and Its Structure
Unit 1 - Overview of The Compiler and Its Structure
Campus
Department of Computer
Compiler Design
Science
Course code: CoSc4072
By: Mekonen M.
Unit one
Introduction to Compiler
Discuss on:
Looping
• What is a programming language? What are the
different categories of programming language?
• What is the translator in the programming language,
list different kinds of translators?
• Why compiler?
• How to source code compiled and run? List steps of
compilation?
At the end of the of study you will able to:
Looping
• Explain the role of a translator in converting high-level
programming languages to machine code.
• Differentiate between various types of translators.
• Comprehend the analysis-synthesis model and its
significance in compilation.
• Identify and explain the key components of the
analysis and synthesis phases.
• Explain the sequential steps involved in the
compilation process.
• Identify the purpose of each phase in the compiler.
Topics to be covered
Looping
• Evolution of programming language
• Translator
• Analysis synthesis model of compilation
• Phases of compiler
• Grouping of the Phases
• Difference between compiler & interpreter
• Context of compiler (Cousins of compiler)
Evolution of computer programming
• 1940’s - the first electronic computers are invented
• They were programmed in machine language by sequences of 0's and 1‘s
• slow, tedious, error prone, machine dependant, hard to understand and modify but fast to
run
• Early 1950's - mnemonic assembly languages developed
• First they were just mnemonic representations of machine instructions, later,
macro instructions were added
latter half of the 1950's - higher-level languages developed
Fortran for scientific computation, Cobol for business data processing, and Lisp for symbolic
computation
Translator
Translator
• A translator is a program that takes one form of program as input and
converts it into another form.
• Types of translators are:
1. Compiler
2. Interpreter
3. Assembler
Source Translator Target
Program Program
Error
Messages (If any)
Mekonen M. # CoSc4072 Unit 1 – Introduction to compiler design 10
Compiler
• A compiler is a program that reads a program written in source language and
translates it into an equivalent program in target language.
Assembly Error
Messages (If any) Machine Code
Code
1. Analysis Phase
2. Synthesis Phase
Lexical analysis
Intermediate Code
code optimization
Syntax analysis generation
Code generation
Semantic analysis
Lexical analysis
Intermediate Code
code optimization
Syntax analysis generation
Code generation
Semantic analysis
id1 +
id2 *
id3 60
Lexical analysis
Intermediate Code
code optimization
Syntax analysis generation
Code generation
Semantic analysis
id2 *
id3 inttoreal
60
Mekonen M. # CoSc4072 Unit 1 – Introduction to compiler design 23
Phases of compiler
Compiler
Lexical analysis
Intermediate Code
code optimization
Syntax analysis generation
Code generation
Semantic analysis
Lexical analysis
Intermediate Code
code optimization
Syntax analysis generation
Code generation
Semantic analysis
Code optimization
Lexical analysis
Intermediate Code
code optimization
Syntax analysis generation
Code generation
Semantic analysis
Code generation
MOV id3, R2
MUL #60.0, R2
MOV id2, R1
ADD R2,R1
MOV R1, id1
Id3R2
Id2R1
Mekonen M. # CoSc4072 Unit 1 – Introduction to compiler design 29
Phases of compiler
Source program
Analysis Phase
Lexical analysis
Syntax analysis
Semantic analysis
Symbol table Error detection
and recovery
Intermediate code
• The compiler may be able to continue with some errors, but other
errors may stop the process
Target Assembly
• Preprocessor Program
• Assembler Assembler
• Linker Relocatable Object
• Loader Code
Libraries & Linker / Loader
Object Files
Absolute Machine
Code
Mekonen M. # CoSc4072 Unit 1 – Introduction to compiler design 38
Context of compiler (Cousins of compiler)
Skeletal Source Program
Preprocessor
Some of the task performed by preprocessor: Preprocessor
Target Assembly
Program
Assembler
Relocatable Object
Code
Libraries & Linker / Loader
Object Files
Absolute Machine
Code
Mekonen M. # CoSc4072 Unit 1 – Introduction to compiler design 40
Context of compiler (Cousins of compiler)
Skeletal Source Program
Assembler
Assembler is a translator which takes the assembly Preprocessor
Target Assembly
Program
Assembler
Relocatable Object
Code
Libraries & Linker / Loader
Object Files
Absolute Machine
Code
Mekonen M. # CoSc4072 Unit 1 – Introduction to compiler design 41
Context of compiler (Cousins of compiler)
Skeletal Source Program
Linker
Linker makes a single program from a several files Preprocessor