LN1 - C1 - Introduction To Compilers
LN1 - C1 - Introduction To Compilers
Introduction to Compilers
- Before a program can be run, it first must be translated into a form in which it can
be executed by a computer.
- The software systems that do this translation are called compilers.
- We will try to learn the different forms of language translators and a high-level
overview of the structure of a typical compiler.
- Compiler: A compiler is a program that can read a program in one language – the
source language – and translate it into an equivalent program in another language
– the target language.
- The name Compiler is primarily used for programs that translate source code from
a high-level programming language to a lower-level language to create an
executable program.
- An important role of the compiler is to report any errors in the source program that
it detects during the translation process.
- An interpreter, however, can usually give better error diagnostics than a compiler,
because it executes the source program statement by statement.
CSE4129: Formal languages and Compilers : Lecture 1
Preprocessor
Compiler
Assembler
Linker/Loader
Structure of a Compiler
1
Lexical Analyzer
Token Stream
2
Syntax Analyzer
Syntax Tree
3
8 Semantic Analyzer 9
Symbol Table
Management Syntax Tree Error handling
4 and recovery
Intermediate Code Generator
Intermediate Representation
5
Machine-Independent Code Optimizer
Intermediate Representation
6
Code Generator
7 Target Machine
Code
Machine-Dependent Code Optimizer
- The structure of a Compiler can be mapped into two parts: Analysis (Front End) and
Synthesis (Back End).
CSE4129: Formal languages and Compilers : Lecture 1
Analysis Phase:
- Analysis phase reads the source program and splits it into multiple tokens and constructs
the intermediate representation of the source program.
- It also checks and indicates the syntax and semantic errors of a source program.
- It collects information about the source program and prepares the symbol table. Symbol
table will be used all over the compilation process.
- This is also called as the front end of a compiler.
Synthesis Phase:
-It will get the analysis phase input (intermediate representation and symbol table) and
produces the targeted machine level code.
-This is also called as the back end of a compiler.
Questions:
1. What is the difference between a compiler and an interpreter?
2. What are the advantages of (a) a compiler over an interpreter (b) an interpreter
over a compiler?