0% found this document useful (0 votes)
68 views37 pages

Theory of Computation & Compiler Design (CSE2002) : - Nitin Singh Rajput

The document discusses the theory of computation and compiler design. It introduces compilers and outlines the phases of a compiler. It discusses lexical analysis, syntax analysis, and semantic analysis, which are parts of analyzing the source program. The main phases of a compiler are listed as lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. Symbol table management and error handling are described as sub-phases of compilers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views37 pages

Theory of Computation & Compiler Design (CSE2002) : - Nitin Singh Rajput

The document discusses the theory of computation and compiler design. It introduces compilers and outlines the phases of a compiler. It discusses lexical analysis, syntax analysis, and semantic analysis, which are parts of analyzing the source program. The main phases of a compiler are listed as lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. Symbol table management and error handling are described as sub-phases of compilers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Theory of Computation & Compiler

Design (CSE2002)
Introduction to Compilers, Analysis of Source
Program & Phases of Compiler

-Nitin Singh Rajput


Outline of this Lecture
 Some Problem Solving on Language Operations
 Introduction to Compilers
 Analysis of Source Program
 Phases of Compiler
Some Problem Solving -1
 Let L = {ab} than find L* and L+
Some Problem Solving -1
 Let L = {ab} than

L* = L0 U L1 U L2 U L3 … …

L* = {ε} U {ab} U {abab} U {ababab} … …

L* = {ε, ab, abab, ababab… …}

L+ = L* - {ε}

= {ab, abab, ababab… …}


Some Problem Solving -2
 Let L = {a, ab} than find L* and L+
Some Problem Solving-2
 Let L = {a, ab} than

L* = L0 U L1 U L2 U L3 … …

L* = {ε} U {a, ab} U {aa, aab, aba, abab} U … …

L* = {ε, a, ab, aa, aab, aba, abab … …}

L+ = L* - {ε}

= {a, ab, aa, aab, aba, abab … …}


Precedence of Operators
1. Kleene Closure, Positive Closure (LHS to RHS)
2. Concatenation
3. Union, Intersection (LHS to RHS)
Some Problem Solving -3
 Let L= {(0 , 1) . 0} than find L*
Some Problem Solving -3
 Let L= {(0, 1) . 0} than

L = {00, 10},
Now,
L* = L0 U L1 U L2 U L3 … …
L* = {ε} U {00, 10} U {0000, 0010, 1000, 1010} , …
L* = {ε, 00, 10, 0000, 0010, 1000, 1010 , …}
Some Problem Solving -4
 Let L1 = {01} than find out the strings for another
language L2 such that L2 = 0. L1*
Some Problem Solving -4
 Let L1= {01} than find out the strings for another
language L2 such that L2 = 0.L1*

 L* = L0 U L1 U L2 U L3 … …
 L1* = {ε} U {01} U {0101} U {010101}… …
 L1* = {ε, 01, 0101, 010101… …}
 L2 = 0.L1*
 L2 = 0. {ε, 01,0101,010101… …}
 L2 = {0, 001, 00101, 0010101… ….}
Defining Automata
The Relationship between

(Input)

Alphabet
Computational Models
(Automaton) & Related Grammar

According to Noam Chomsky, there are four types of grammars


Chomsky Hierarchy for
Languages
What is Compiler?

 As defined earlier, Compiler is a program that


converts a language (source code) to another
language (target code).

Source Target
Code
Compiler Code
What is the difference between
Compiler & Interpreter
Parts of Compilation
 There are two parts of Compilation:
1. Analysis
2. Synthesis

 Analysis part breaks down the source code into


constituent pieces and generates an intermediate
representation (code) of a source code.
 Synthesis part constructs the desired target code
from the intermediate code.
Pictorial Representation

Source Code

Analysis

Intermediate Code

Synthesis

Target Code
Analysis of Source Program

Source Code
Parts of Analysis
Lexical Syntax Semantic
Analysis Analysis Analysis Analysis

Intermediate Code

Synthesis

Target Code
Lexical Analysis
Syntax Analysis
Semantic Analysis
Phases of Compiler
 Compiler operates in phases

 Each of this phase transforms the source program


from one representation to another

 There are 6 phases of a compiler and 2 sub phases


of a compiler.
Phases of Compiler
 Main Phases
1. Lexical Analysis
2. Syntax Analysis
3. Semantic Analysis
4. Intermediate Code Generation
5. Code Optimization
6. Code Generation

 Sub phases of Compilers


1. Symbol Table Management
2. Error Handling
Source Code

Target Code
Lexical Analysis
Syntax Analysis
Semantic Analysis
Intermediate Code Generation
Code Optimization
Code Generation
Symbol Table
Error Handling
Any Query ???
Thank you

You might also like