0% found this document useful (0 votes)
66 views

Course Title: Compiler Design Course Code: CS 451 Topic: Introduction Branch: CSE Semester: VII TH

This document provides an overview of the compiler design course including the topic, branch, semester, objectives, and phases of compilation. The key phases discussed are lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation, symbol table management, and error detection/handling. The overall goal of the course is to discuss the principles and techniques for analyzing and synthesizing programs during compilation.

Uploaded by

Siddhu Siddharth
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Course Title: Compiler Design Course Code: CS 451 Topic: Introduction Branch: CSE Semester: VII TH

This document provides an overview of the compiler design course including the topic, branch, semester, objectives, and phases of compilation. The key phases discussed are lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation, symbol table management, and error detection/handling. The overall goal of the course is to discuss the principles and techniques for analyzing and synthesizing programs during compilation.

Uploaded by

Siddhu Siddharth
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Course Title: Compiler Design

Course Code: CS 451

Topic : Introduction

Branch : CSE Semester : VII th

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
This presentation is released under Creative Commons-A6ribute,on 4.0 License. You are free to use, distribute and modify it ,
including for commercial purposes, provided you acknowledge the source.
Text and Reference books
• 1. Compilers Principles, Techniques and Tools. Aho
A. V., Lam M. S., Sethi R. & Ullman J. D. 2nd Ed.
Pearson. 2009.

• 2. Principles of Compiler Design. Aho A. V. &


Ullman J. D. Narosa Publishing House. 1999.
•  
• 3. Compiler Design in C. Holub A. I. 2nd Ed.
Prentice-Hall of India. 2008.
Objective of the course
• This course discuss the principle and technique
involved in the designing of analysis and synthesis
phases of compilation.
• It also design and implementation of a lexical
analyzer, syntax analyzer, semantic analyzer, code
generation schemes ,type checking and for the
optimization of codes and run-time environment.
• The objective of the laboratory in compiler designing
is to learn LEX and YACC programming.
Compiler
• Compiler is a program that read a program in one
language (source program) and translate it into an
equivalent program in another language (target
program). The compiler takes the source program as
High Level Language and translate it into machine
level language. During the translation process if any
error detects in the source program compiler report
them as error message.

Source Program Compiler Target Program


Interpreter

Source Program
Interpreter Result

Input

• Advantages of Interpreter
• Comparison of Compiler, Interpreter and assembler
Language Processing system

Source Program
Preprocessor
Modified Source program
Compiler
Target assembly program
Assembler
Relocatable machine code
Linker / Loader Library files
Relocatable object files
Target Machine code
Process of Compiling
Characters Stream
Lexical Analyzer
Token Stream
Syntax Analyzer
Parse/syntax tree
Semantic Analyzer
Syntax tree Error detection &
Symbol Table handling
Intermediate Code Generator
Intermediate code
Machine Independent Code optimizer
Intermediate code
Code generator
Target Machine code
Machine Dependent Code optimizer
Introduction to compiler
Target Machine code
Chapter 1 7
The Phases of Compiler
• Lexical Analysis
• Syntax Analysis
• Semantic Analysis
• Intermediate Code Generation
• Code Optimization
• Code Generation
• Symbol table management
• Error Detection and handling.
Introduction to compiler
Chapter 1 8
Compiler: Analysis-Synthesis Model

• There are two parts of the compilation:-


• Analysis Phase : Source program
– Lexical analyzer
– Syntax analyzer
– Semantic analyzer
• Synthesis Phase: Target machine code
– Intermediate code generator
– Code optimizer
– Code generator
The Phases of Compiler
• Lexical Analysis : The lexical analysis is also
called scanning. It is the phase of compilation
in which the complete source code is scanned
and your source program is broken up into
group of strings called token.
• A Token is a sequence of characters having a
collective meaning.
• Total=count+rate*10
Introduction to compiler
Chapter 1 10
The Phases of Compiler
• Syntax Analysis : The syntax analysis is also
called parsing. In this phase the token
generated by the lexical analysis are grouped
together to form a hierarchical structure. The
syntax analysis determine the structure of
the source string by grouping the tokens
together. The hierarchical structure
generated in this phase is called parse tree or
syntax tree.
Introduction to compiler
Chapter 1 11
The Phases of Compiler
• Semantic Analysis : Once the syntax is
checked in the syntax analyser phase the
semantic analysis determine the meaning of
the source string.
• It gets input from the syntax analysis as a
parse tree and check whether the given
syntax is correct or not.
• It perform type conversion of all the data
types into real data types.
Introduction to compiler
Chapter 1 12
The Phases of Compiler
• Intermediate Code Generation: The
intermediate code is a kind of code which is
easy to generate and this code can be easily
converted to target code.
• It gets input from the semantic analysis and
converts the input into output as
intermediate code such as three- address
code which consist a sequence of instruction
with three operands.
Introduction to compiler
Chapter 1 13
The Phases of Compiler
• Code Optimization: The code optimization
phase attempts to improve the intermediate
code. Thus by optimizing the code the overall
running time of target program can be
improved.
• It reduced the redundant code and attempts
to improve the intermediate code so that
faster running machine code will result. The
optimization involves
Introduction to compiler
Chapter 1 14
The Phases of Compiler
• Deduction and removal of dead code
• Calculation of constants in expressions and
terms
• Collapsing of repeated expression into
temporary string.
• Loop unrolling
• Moving code outside the loop.

Introduction to compiler
Chapter 1 15
The Phases of Compiler
• Code Generation : In code generation phase
the target code gets generated. The
intermediate code instructions are translated
into sequence of machine instructions.

Introduction to compiler
Chapter 1 16
The Phases of Compiler
• Symbol table Management : The task of
symbol table is to store identifiers used in
program.
• The symbol table also stores information
about attributes of each identifier. The
attributes of identifiers are usually its type,
its scope, information about the storage
allocated for it.
• It also store information about the
subroutines used in the program.
Introduction to compiler
Chapter 1 17
The Phases of Compiler
• Symbol table allows us to find the record for
each identifier quickly, and to store or
retrieve data from the record efficiently.
• During compilation the lexical analyzer
detects the identifier and makes its entry in
the symbol table.

Introduction to compiler
Chapter 1 18

The Phases of Compiler
Error detection and handling : In compilation,
each phase detects errors. These errors must
be reported to error handler whose task is to
handle the errors so that the compilation can
proceed. Normally, the errors are reported in
the form of message. Ex. In Lexical analysis,
error occurs in separation of tokens. In syntax
analysis error occurs during construction of
parse tree.

Introduction to compiler
Chapter 1 19

The Phases of Compiler
Error detection and handling : In compilation,
each phase detects errors. These errors must
be reported to error handler whose task is to
handle the errors so that the compilation can
proceed. Normally, the errors are reported in
the form of message. Ex. In Lexical analysis,
error occurs in separation of tokens. In syntax
analysis error occurs during construction of
parse tree.

Introduction to compiler
Chapter 1 20
Examples(Phases of compiler)
Examples(Phases of compiler)
References
• 1. John E. Hopcroft, Rajeev Motwani & Jeffery D. Ullman.
Introduction to Automata Theory, Languages and
Computation. Pearson Education.
• 2. K.L.P Mishra and N.Chandrasekaran, Theory of
Computer science (Automata, Language and
Computation) PHI
• .

You might also like