Professional Documents
Culture Documents
Unit - 1
Introduction to
Compiler
Translator
Language Translator
Cousins of Compiler
Phases of Compiler
Grouping of Phases
Types of Compiler
What it is?
Why it is required?
Semantic Gap
Application Execution
domain To fill this gape domain
semantic rules are
required
Translator
Programming
Application Execution
Language
domain domain
domain
Translator
Language Translator
Cousins of Compiler
Phases of Compiler
Grouping of Phases
Types of Compiler
Source: https://www.nesoacademy.org/
Language Translator
Source: https://www.nesoacademy.org/
Compiler
Programming Programming languages that use Programming languages that uses interpreter
languages compilers include C, C++, C#, etc.. include Python, Ruby, Perl, MATLAB, etc.
Types of Compiler can check syntactic and Interpreter checks the syntactic errors only.
errors semantic errors in the program
detected simultaneously.
Translation Processor /
Context of Compiler /
Cousins of Compiler
Language Processor System... Internal Architecture
Source: https://www.nesoacademy.org/
Language Processor System... Internal Architecture
Preprocessor
“Rational” augment older languages with more modern flow of control and
Preprocessor data structuring facilities.
Compiler
Source: https://www.nesoacademy.org/
Language Processor System... Internal Architecture
Assembler
in phase one identifying the identifiers and store them into the symbol table
in second phase translation of each operation code and identifiers into sequence
of bits and specific location respectively
Language Processor System... Internal Architecture
Assembler
Source: https://www.nesoacademy.org/
Language Processor System... Internal Architecture
Loader and Link Editor
A program called loader performs the two functions of loading and link editing
The process of loading consist of taking relocatable machine code, altering the
relocatable address and placing the altered instructions and data in memory at the
proper location.
Linker allows us to make a single program from several files of relocatable machine
code.
Source: https://www.nesoacademy.org/
Translator
Language Translator
Cousins of Compiler
Phases of Compiler
Grouping of Phases
Types of Compiler
ANALYSIS
PHASE
ANALYSIS – SYNTHESIS
MODEL OF COMPILATION
SYNTHESIS
PHASE
The Phases of Compilers… LEXICAL ANALYSIS
In this phase, input character from source code is read from left to right and then
break into stream of units.
So, Token is the smallest meaningful entities of program are produced as output
The Phases of Compilers… LEXICAL ANALYSIS
Source:
https://www.nesoacademy.org/
The Phases of Compilers… SYNTAX ANALYSIS
It creates syntax tree from generated tokens if the code is error free.
Syntax tree consist operators as internal node and operands as leaf node.
This phase check each and every line and try to detect errors if it is grammatically
(syntax wise) not correct.
The Phases of Compilers… SYNTAX ANALYSIS
Source: https://www.nesoacademy.org/
The Phases of Compilers… SEMANTIC ANALYSIS
Source: https://www.nesoacademy.org/
The Phases of Compiler…INTERMEDIATE CODE GENERATOR
Source: https://www.nesoacademy.org/
The Phases of Compiler…CODE OPTIMIZATION
This phase improves the intermediate code, in such a way that a machine
code can be produced, which occupies less memory space and less
execution time without changing the functionality or correctness of program.
The Phases of Compiler…CODE OPTIMIZATION
Source: https://www.nesoacademy.org/
The Phases of Compiler…CODE GENERATOR
Source: https://www.nesoacademy.org/
The Phases of Compiler…
• pos (identifier) E → E := E
:=
• := (assignment symbol)
• initial (identifier)
Syntax pos + E → E + E
• + (plus sign) Analysis
• rate (identifier) initial * E → E * E
• * (multiplication sign)
• 60 (number) rate 60 E → NUM
pos + E → E + E initial *
Semantic (real)
Analysis
initial * E → E * E rate inttoreal
(real)
rate 60 E → NUM
60
(integer)
syntax tree for
pos := initial + rate * 60
The Phases of Compiler…
Intermediate Code
Three-Address Code : pos := initial + rate * 60
Generation
Code Optimization
/* natural code */
temp1 := inttoreal(60)
temp2 := id3 * temp1
/* original code, where id1,
temp3 := id2 + temp2
id2, and id3 are reals */
id1 := temp3
id1 := id2 + id3 * 60
/* optimized code */
temp1 = id3 * 60.0
id1 := id2 + temp1
The Phases of Compiler…
Code Generation
/* assembly code */
/* optimized intermediate code */ MOVF id3, R2
temp1 = id3 * 60.0 MULF #60.0, R2
id1 := id2 + temp1 MOVF id2, R1
ADDF R2, R1
Symbol table is the data structure which contains a record for each identifier with its attribute
list.
As a identifier identified by scanner (lexical analyzer) it will be entered into symbol table
Essential function of compiler is to record the identifiers with its attributes (type, scope,
storage location, etc.)
In the case of function attributes are return type, no. & type of parameters, parameter
passing scheme.
Error Detection and Recovery
Each phase can have errors so it has to deal with those errors so that
next phase of compilers may proceeds and next errors to be detected.
Syntax analyze phase detect error where token stream violates the
structure rules of the language.
Semantic phase tries to detect construct that having the right syntactic
structure but no meaning.
Translator
Language Translator
Cousins of Compiler
Phases of Compiler
Grouping of Phases
Pass and Phase
Types of Compiler
ANALYSIS
PHASE
SYNTHESIS
PHASE
The Grouping of Phases…ANALYSIS PHASE
Front end consist of those phase, that depends preliminary on the source
language & are independent of the target machine.
The front end also includes error handling that goes along with each of
these phases.
The Grouping of Phases…SYNTHESIS PHASE
One can take the front end of a compiler and redo its associated back
end to produce a compiler for the same source language on a different
machine.
Language Translator
Cousins of Compiler
Phases of Compiler
Grouping of Phases
PASS PHASE
Language Translator
Cousins of Compiler
Phases of Compiler
Grouping of Phases
Types of Compiler
Compiler construction tools
Types of Compilers
Native Compiler
Cross Compiler
Incremental Compiler
Parallelizing Compiler
Native Compiler
The compiler that takes high-level language code as input and outputs source
code of another high- level language only.
Unlike other compilers which convert high level language into low level machine
language, it can take up a code written in Pascal and can transform it into C-
conversion of one high level language into another high level language having
same type of abstraction .
Language Translator
Cousins of Compiler
Phases of Compiler
Grouping of Phases
Types of Compiler
Parser Generator