2. Table of Contents
Introduction
The structure of Compiler(All phases)
All Phases of Compiler
1
Compiler & its Application
Compiler vs Interpreter
Symbol Table Management
4. Introduction
3
A compiler translates the code written in one
language to some other language without
changing the meaning of the program. It is
also expected that a compiler should make
the target code efficient and optimized in
terms of time and space
5. Compiler & its Application
4
A compiler is a program that reads a
program written in one language and
translates is into an equivalent program
in another language.
What is compiler ?
6. Compiler & its Application cont..
5
Application of compiler
Implementation of High-Level Programming
Optimizations for Computer Architectures
Design of New Computer Architectures
Program Translations
Software Productivity Tools
7. Compiler vs Interpreter
6
1.Compiler scans the entire program and
translate the whole it into machine code.
1.Interpreter translates just one statement
of the program at time into machine code
2.Compiler takes a lot of time to anaylize the
source code .however , the overall time
taken to execute the process is much faster.
2.An interpreter takes vary less time to
anaylize the source code .however, overall
time to execute the process is much slower.
3.Compiler are used by program language
like C and C++ for example
3.Interpreter are used by programming
language like Ruby and python for example
8. The Structure of Compiler (all phase )
7
Lexical Analyzer
Syntax Tree
Semantic Analyzer
Character stream
Intermediate code
generation
Code Optimizer
Code Generator
Symbol Table
manager
Error Handler
9. Lexical analysis coverts source program into a stream of
valid word of the language, known as token.
Lexical analyzer also known as(Lexer ,Scanner,Tokening )
8
Lexical Analyzer
Function of lexical
Analyzer
Convert the source code into stream of token.
Removing white space , comments
Recognizing keyword , identifier, Contents
Show error when then lexeme doesn’t match of
patten
All phase of Compiler
10. Syntax of a language refers to the structure of valid program or
statement of the language.
Specified using certain rules known as Productions
Collection of such productions(rules) is known as grammar.
Syntax Tree
9
Function of syntax
tree
Syntax analysis to verified that a string of token valid or not.
report syntactic error.
recovery from such error so as to continuous to execution
process
All phase of Compiler (cont..)
11. Semantic Analysis makes sure that declarations and statements
of program are semantically correct. It is a collection of
procedures which is called by syntax tree as and when required by
grammar. Both syntax tree and symbol table are used to check
the consistency of the given code.
Semantic Analyzer
10
Function of syntax
tree Semantic error :Type mismatch, Undeclared variables,
Reserved identifier.
Type Checking: Ensures that data types are used in a way
consistent with their definition.
Label Checking –A program should contain labels
references.
All phase of Compiler (cont..)
12. Semantic Analysis makes sure that declarations and statements
of program are semantically correct. It is a collection of
procedures which is called by syntax tree as and when required
by grammar. Both syntax tree and symbol table are used to
check the consistency of the given code.
Intermediate code generation
11
Postfix Notation
Three-Address Code
Syntax
Intermediate code representation
All phase of Compiler (cont..)
13. Optimization is a program transformation technique, which tries
to improve the code by making it consume less resources example
CPU, Memory and deliver high speed. In optimization, high-level
general programming constructs are replaced by very efficient
low-level programming codes
Code Optimizer
12
Code generation can be considered as the final phase
of compilation. Through post code generation,
optimization process can be applied on the code
Code Generator
All phase of Compiler (cont..)
14. 1
13
Symbol Table Manager
Symbol table is an important data structure created and maintained
by compilers in order to store information about the occurrence of
various entities such as variable names, function names, objects,
classes, interfaces, etc. Symbol table is used by both the analysis
and the synthesis parts of a compiler.
15. 1
14
Derivation
derivation is used to find whether the string
belongs to a given grammar.
Type of Derivation
1. Leftmost derivation.
2. Rightmost derivation
17. 1
16
A compiler translates the code written in one language to some other
language without changing the meaning of the program. It is also
expected that a compiler should make the target code efficient and
optimized in terms of time and space. Compiler design principles provide
an in-depth view of translation and optimization process.
Conclusion