SlideShare a Scribd company logo
Introduction of
Compiler
UNIT I & II
UNIT I Compiling TAMILSELVI T 2
COMPILERS
 Compilers are basically a Translators
 A compiler is a program takes a program written in a source
language and translates it into an equivalent program in a target
language.
UNIT I Compiling TAMILSELVI T 3
Analysis of Source Program
 Analysis consists of three phases:
 Linear Analysis (Lexical Analysis or Scanning)

Group the source string into Tokens
 Hierarchical Analysis (Syntax Analysis or Parsing)

Tokens are grouped into nested collections
 Semantic Analysis

Ensure the correctness of the source program
UNIT I Compiling TAMILSELVI T 4
Phases of Compiler
UNIT I Compiling TAMILSELVI T 5
Lexical Analysis
 Linear Analysis (Lexical Analysis or Scanning)
 Scan the complete source code
 Source program is broken up into group of strings called tokens
Example: position := initial+rate*60

The identifier position

The Assignment Symbol

The identifier initial

The plus sign

The identifier rate

The multiplication sign

The constant 60
UNIT I Compiling TAMILSELVI T 6
Syntax Analysis
 Hierarchical Analysis (Parsing)
 Grouping the tokens into grammatical Phrases
 Grammatical Phrases are represented by Parse Tree or Syntax
Tree
UNIT I Compiling TAMILSELVI T 7
Semantic Analysis
 Type checking
 checks the source program for semantic errors
 collects the type information
UNIT I Compiling TAMILSELVI T 8
Intermediate Code Generation
 Three Address Code
 Sequence of instructions each of which has atmost three
operands
 Properties:
 Easy to produce
 Easy to translate into target program
Example
t1 := inttoreal(60)
t2 := id3*t1
t3 := id2+t2
id1 := t3
UNIT I Compiling TAMILSELVI T 9
Code Optimization
 Improve the intermediate code (Improve the running time of the
target program)
Example
t1 := id3*60.0
id1 := id2+t1
UNIT I Compiling TAMILSELVI T 10
Code Generation
 Intermediate code instruction are translated into sequence of
machine instruction
 Example
MOVF id3,R2
MULF #60.0,R2
MOVF id2,R1
ADDF R2,R1
MOVF R1,id1
UNIT I Compiling TAMILSELVI T 11
Symbol Table Management
 A data structure containing a record for each identifier
 Stores the information about the attributes of all identifiers
 Attributes : name, type, size etc.
Error Detection and Handling
 It detects and handle the errors (Syntax error, Semantic errors)
 Errors are reported in the form of messages
UNIT I Compiling TAMILSELVI T 12
Cousins of Compiler
 Preprocessors
 Macro processing
 File inclusion
 Assemblers
 Loaders and Link-Editors
UNIT I Compiling TAMILSELVI T 13
Grouping of Phases
 Front end
 Primarily depends on the source language and independent
on the target language
 It includes lexical analysis, Syntax analysis and semantic
analysis
 Back end
 Primarily depends on the target language and independent
on the source language
 It includes code generation and code optimization
UNIT I Compiling TAMILSELVI T 14
Compiler Construction Tools
 Parser Generator
 Scanner Generator
 Syntax directed translation Engine
 Automatic code generator
 Data flow engine
UNIT I Compiling TAMILSELVI T 15
Lexical Analysis
 Input is scanned completely to identify the tokens
 Tokens (Logical unit)
 Identifier, Keywords, operators etc.
UNIT I Compiling TAMILSELVI T 16
Specification of Tokens
 Strings and Languages

Finite sequence of Symbols is called Strings

Set of strings over some alphabet is called Language
 Operation on Languages

Concatenation:
 L1L2 = { s1s2| s1∈ L1 and s2∈ L2}

Union
 L1 ∪ L2 = { s| s∈ L1 or s∈ L2}

Kleene Closure
 L* =

Positive Closure
 L+ =
 Regular Expressions

∞
=1i
i
L

∞
=0i
i
L
UNIT I Compiling TAMILSELVI T 17
Regular Expression
 Notation for representing Tokens
 Ex: Identifiers in Pascal
letter → A | B | ... | Z | a | b | ... | z
digit → 0 | 1 | ... | 9
id → letter (letter | digit ) *
UNIT I Compiling TAMILSELVI T 18
Recognition of Tokens
 Finite Automata
 DFA –
 NFA –
10 2
a b
start
a
b
10 2
ba
b
b a
UNIT I Compiling TAMILSELVI T 19
Questions
Part -A
 What are the issues of Lexical analyzer?
 Define compiler.
 What is preprocessor?
 What is finite automata?
 Draw the transition diagram to represent relational operators.
 Define Lexeme, pattern.
Part -B
 Explain the various phases of compiler.
 Explain the compiler construction tools.
 Explain input buffering in detail
 Write and explain about specification of tokens
 Construct NFA from the regular expression.

More Related Content

PPTX
Compiler Chapter 1
PPT
Analysis of the source program
PPSX
Spr ch-05-compilers
PPT
Lexical analyzer
PPTX
The analysis synthesis model of compilation
PPT
Cpcs302 1
PPT
phases of a compiler
PPTX
Compiler Construction
Compiler Chapter 1
Analysis of the source program
Spr ch-05-compilers
Lexical analyzer
The analysis synthesis model of compilation
Cpcs302 1
phases of a compiler
Compiler Construction

What's hot (20)

PDF
P code
PPT
Compiler Construction
PPTX
phases of compiler-analysis phase
PDF
Phases of the Compiler - Systems Programming
PPTX
Compiler Design
PPT
what is compiler and five phases of compiler
DOCX
Compiler Design Material
PPT
Compiler1
KEY
Unit 1 cd
PPTX
Phases of compiler
PDF
Different phases of a compiler
PDF
Compiler design
PPTX
7 compiler lab
PDF
Compiler unit 1
PPTX
Structure of the compiler
PPT
Principles of compiler design
PPSX
Compiler designs presentation final
PDF
Cs6660 compiler design
PPTX
Compiler Engineering Lab#1
PPTX
Workshop Assembler
P code
Compiler Construction
phases of compiler-analysis phase
Phases of the Compiler - Systems Programming
Compiler Design
what is compiler and five phases of compiler
Compiler Design Material
Compiler1
Unit 1 cd
Phases of compiler
Different phases of a compiler
Compiler design
7 compiler lab
Compiler unit 1
Structure of the compiler
Principles of compiler design
Compiler designs presentation final
Cs6660 compiler design
Compiler Engineering Lab#1
Workshop Assembler
Ad

Viewers also liked (20)

PPTX
Chapter one
PPTX
IS 151 Lecture 3
PPT
IS 139 Lecture 7
PPTX
IS 151 - Lecture 3
PPT
Truth table analysis
PPTX
IS 151 Lecture 2
PPT
pointer, structure ,union and intro to file handling
PPTX
aaالمملكة العربية السعودية
PPT
Compiler interpreter and_bootstrapping
PPTX
Logical and Conditional Operator In C language
PPTX
C Structures and Unions
PPT
Logic gates
PPTX
Hierarchical Memory System
PPT
C Structures & Unions
PPTX
Memory Hierarchy
PPT
Truth tables
PPT
PPTX
PDF
Introduction to compilers
Chapter one
IS 151 Lecture 3
IS 139 Lecture 7
IS 151 - Lecture 3
Truth table analysis
IS 151 Lecture 2
pointer, structure ,union and intro to file handling
aaالمملكة العربية السعودية
Compiler interpreter and_bootstrapping
Logical and Conditional Operator In C language
C Structures and Unions
Logic gates
Hierarchical Memory System
C Structures & Unions
Memory Hierarchy
Truth tables
Introduction to compilers
Ad

Similar to Cd unit i (20)

PPTX
Introduction to Compilers
PDF
unit1pdf__2021_12_14_12_37_34.pdf
PPTX
Phases of Compiler.pptx
PPTX
Compiler an overview
PDF
Compiler design Introduction
PPTX
ppt_cd.pptx ppt on phases of compiler of jntuk syllabus
PPT
Unit1.ppt
PPTX
COMPILER DESIGN PPTS.pptx
PDF
Chapter1pdf__2021_11_23_10_53_20.pdf
PPTX
CD U1-5.pptx
PPTX
Unit 1.pptx
PDF
C compiler(final)
PPTX
Unit-1compiler design and its lecture note .pptx
PPTX
A Lecture of Compiler Design Subject.pptx
PDF
Compilers Design
PPTX
Compiler Design Introduction With Design
PPTX
unit1_cd unit1_cd unit1_cd unit1_cd unit1_cd (1).pptx
PPTX
UNIT 1 COMPILER DESIGN TO BE ENHANCE THEIR FEATURES AND BEHAVIOURS.pptx
PDF
Lecture 01 introduction to compiler
PDF
Compiler Design Introduction
Introduction to Compilers
unit1pdf__2021_12_14_12_37_34.pdf
Phases of Compiler.pptx
Compiler an overview
Compiler design Introduction
ppt_cd.pptx ppt on phases of compiler of jntuk syllabus
Unit1.ppt
COMPILER DESIGN PPTS.pptx
Chapter1pdf__2021_11_23_10_53_20.pdf
CD U1-5.pptx
Unit 1.pptx
C compiler(final)
Unit-1compiler design and its lecture note .pptx
A Lecture of Compiler Design Subject.pptx
Compilers Design
Compiler Design Introduction With Design
unit1_cd unit1_cd unit1_cd unit1_cd unit1_cd (1).pptx
UNIT 1 COMPILER DESIGN TO BE ENHANCE THEIR FEATURES AND BEHAVIOURS.pptx
Lecture 01 introduction to compiler
Compiler Design Introduction

Recently uploaded (20)

PDF
August Patch Tuesday
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Hybrid model detection and classification of lung cancer
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Hindi spoken digit analysis for native and non-native speakers
August Patch Tuesday
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Enhancing emotion recognition model for a student engagement use case through...
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Hybrid model detection and classification of lung cancer
A comparative study of natural language inference in Swahili using monolingua...
Zenith AI: Advanced Artificial Intelligence
MIND Revenue Release Quarter 2 2025 Press Release
NewMind AI Weekly Chronicles - August'25-Week II
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
A comparative analysis of optical character recognition models for extracting...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
cloud_computing_Infrastucture_as_cloud_p
Hindi spoken digit analysis for native and non-native speakers

Cd unit i

  • 2. UNIT I Compiling TAMILSELVI T 2 COMPILERS  Compilers are basically a Translators  A compiler is a program takes a program written in a source language and translates it into an equivalent program in a target language.
  • 3. UNIT I Compiling TAMILSELVI T 3 Analysis of Source Program  Analysis consists of three phases:  Linear Analysis (Lexical Analysis or Scanning)  Group the source string into Tokens  Hierarchical Analysis (Syntax Analysis or Parsing)  Tokens are grouped into nested collections  Semantic Analysis  Ensure the correctness of the source program
  • 4. UNIT I Compiling TAMILSELVI T 4 Phases of Compiler
  • 5. UNIT I Compiling TAMILSELVI T 5 Lexical Analysis  Linear Analysis (Lexical Analysis or Scanning)  Scan the complete source code  Source program is broken up into group of strings called tokens Example: position := initial+rate*60  The identifier position  The Assignment Symbol  The identifier initial  The plus sign  The identifier rate  The multiplication sign  The constant 60
  • 6. UNIT I Compiling TAMILSELVI T 6 Syntax Analysis  Hierarchical Analysis (Parsing)  Grouping the tokens into grammatical Phrases  Grammatical Phrases are represented by Parse Tree or Syntax Tree
  • 7. UNIT I Compiling TAMILSELVI T 7 Semantic Analysis  Type checking  checks the source program for semantic errors  collects the type information
  • 8. UNIT I Compiling TAMILSELVI T 8 Intermediate Code Generation  Three Address Code  Sequence of instructions each of which has atmost three operands  Properties:  Easy to produce  Easy to translate into target program Example t1 := inttoreal(60) t2 := id3*t1 t3 := id2+t2 id1 := t3
  • 9. UNIT I Compiling TAMILSELVI T 9 Code Optimization  Improve the intermediate code (Improve the running time of the target program) Example t1 := id3*60.0 id1 := id2+t1
  • 10. UNIT I Compiling TAMILSELVI T 10 Code Generation  Intermediate code instruction are translated into sequence of machine instruction  Example MOVF id3,R2 MULF #60.0,R2 MOVF id2,R1 ADDF R2,R1 MOVF R1,id1
  • 11. UNIT I Compiling TAMILSELVI T 11 Symbol Table Management  A data structure containing a record for each identifier  Stores the information about the attributes of all identifiers  Attributes : name, type, size etc. Error Detection and Handling  It detects and handle the errors (Syntax error, Semantic errors)  Errors are reported in the form of messages
  • 12. UNIT I Compiling TAMILSELVI T 12 Cousins of Compiler  Preprocessors  Macro processing  File inclusion  Assemblers  Loaders and Link-Editors
  • 13. UNIT I Compiling TAMILSELVI T 13 Grouping of Phases  Front end  Primarily depends on the source language and independent on the target language  It includes lexical analysis, Syntax analysis and semantic analysis  Back end  Primarily depends on the target language and independent on the source language  It includes code generation and code optimization
  • 14. UNIT I Compiling TAMILSELVI T 14 Compiler Construction Tools  Parser Generator  Scanner Generator  Syntax directed translation Engine  Automatic code generator  Data flow engine
  • 15. UNIT I Compiling TAMILSELVI T 15 Lexical Analysis  Input is scanned completely to identify the tokens  Tokens (Logical unit)  Identifier, Keywords, operators etc.
  • 16. UNIT I Compiling TAMILSELVI T 16 Specification of Tokens  Strings and Languages  Finite sequence of Symbols is called Strings  Set of strings over some alphabet is called Language  Operation on Languages  Concatenation:  L1L2 = { s1s2| s1∈ L1 and s2∈ L2}  Union  L1 ∪ L2 = { s| s∈ L1 or s∈ L2}  Kleene Closure  L* =  Positive Closure  L+ =  Regular Expressions  ∞ =1i i L  ∞ =0i i L
  • 17. UNIT I Compiling TAMILSELVI T 17 Regular Expression  Notation for representing Tokens  Ex: Identifiers in Pascal letter → A | B | ... | Z | a | b | ... | z digit → 0 | 1 | ... | 9 id → letter (letter | digit ) *
  • 18. UNIT I Compiling TAMILSELVI T 18 Recognition of Tokens  Finite Automata  DFA –  NFA – 10 2 a b start a b 10 2 ba b b a
  • 19. UNIT I Compiling TAMILSELVI T 19 Questions Part -A  What are the issues of Lexical analyzer?  Define compiler.  What is preprocessor?  What is finite automata?  Draw the transition diagram to represent relational operators.  Define Lexeme, pattern. Part -B  Explain the various phases of compiler.  Explain the compiler construction tools.  Explain input buffering in detail  Write and explain about specification of tokens  Construct NFA from the regular expression.

Editor's Notes

  • #2: Module 1.3 – Data Protection: RAID