lect01
lect01
2 Dec 2024 1
Introduction
– Any program written in a programming language must be
translated before it can be executed. This translation is
typically accomplished by a software system called
translator.
– Formally, a translator is a program that takes as input a
program written in programming language (i.e. source
code) and produces as output a program in another
language (i.e. object code or target language).
Source program
Translator
Target program
2 Dec 2024 2
Introduction
Source program Source program
Compiler Interpreter
2 Dec 2024 4
Other translators
Pre-processor Assembler
Pre-processor
Pure HLL
Compiler
Assembly Language
Assembler
M/C Code (Relocatable)
Loader/Linker
Exe/absolute
Machine code
2 Dec 2024 9
Execution of a Program
HLL
Pre-processor
Pure HLL
Compiler
Assembly Language
Assembler
M/C Code (Relocatable)
Loader/Linker
Exe/absolute
Machine code
2 Dec 2024 10
Execution of a Program
HLL
Pre-processor
Pure HLL
Compiler
Assembly Language
Assembler
M/C Code (Relocatable)
Loader/Linker
Exe/absolute
Machine code
2 Dec 2024 11
Execution of a Program
HLL
Pre-processor
Pure HLL
Compiler
Assembly Language
Assembler
M/C Code (Relocatable)
Loader/
Linker
Exe/absolute
Machine code
2 Dec 2024 12
Phases (or structure) of
Compiler
2 Dec 2024 13
HLL
Lexical analysis
Stream of tokens
Syntax analysis
Parse tree
Assembly
2 Dec 2024 Code 14
HLL
Lexical analysis
Stream of tokens
Syntax analysis
Parse tree
Assembly
2 Dec 2024 code 15
HLL
Lexical analysis
Stream of tokens
Syntax analysis
Parse tree
Assembly
2 Dec 2024 code 16
HLL
Lexical analysis
Stream of tokens
Syntax analysis
Parse tree
Exe/absolute
2 Dec 2024 Machine code 17
HLL
Lexical analysis
Stream of tokens
Syntax analysis
Parse tree
Assembly
2 Dec 2024 code 18
HLL
Lexical analysis
Stream of tokens
Syntax analysis
Parse tree
Assembly
2 Dec 2024 Code 19
HLL
Lexical analysis
Stream of tokens
Syntax analysis
Parse tree
Code generation
Exe/absolute
2 Dec 2024 Machine code 20
HLL
Lexical analysis
Stream of tokens
Syntax analysis
Parse tree
Code generation
Exe/absolute
2 Dec 2024 Machine code 21
Phases with example
2 Dec 2024 22
2 Dec 2024 23
Qualities of a Good Compiler
What qualities would you want in a compiler?
– generates correct code (first and foremost!)
– generates fast code
– conforms to the specifications of the input language
– copes with essentially arbitrary input size, variables, etc.
– compilation time (linearly)proportional to size of source
– good diagnostics
– consistent optimisations
– works well with the debugger