Principles of Compiler Design: Unit I
Principles of Compiler Design: Unit I
DESIGN
UNIT I
Compilers and Interpreters
• “Compilation”
– Translation of a program written in a source
language into a semantically equivalent
program written in a target language
Input
Source Target
Compiler
Program Program
• “Interpretation”
– Performing the operations implied by the
source program
Source
Program
Interpreter Output
Input
Error messages
The Analysis-Synthesis Model of
Compilation
Preprocessor
Source Program
Compiler Try for example:
gcc -v myprog.c
Target Assembly Program
Assembler
Relocatable Object Code
Linker Libraries and
Relocatable Object Files
Absolute Machine Code
The Phases of a Compiler
Phase Output Sample
Programmer (source code Source string A=B+C;
producer)
Scanner (performs lexical Token string ‘A’, ‘=’, ‘B’, ‘+’, ‘C’,
analysis) ‘;’
And symbol table with names
Parser (performs syntax analysis Parse tree or abstract syntax ;
|
based on the grammar of the tree =
programming language) / \
A +
/ \
B C