SlideShare a Scribd company logo
1 of 8
Compiler Construction
By Noor wali khan
UOCH
Continue
from
Previous
Lecture
Error Handler
• An error is an abnormal condition in source program, which
either stope the compilation or generate undesired results.
• A compiler must not stop at each error.
• It must somehow handle the error, so that compilation
proceeds up to the end of the program.
• At the end a list of errors messages is provided to the user.
• This is the job of the error handler, and also marks the place
where the errors occur.
Error Handler
• Error handler contains a set of routines for handling error
encountered in any phase of the compiler.
• The basic tasks of the compiler are:
• Detection
• Reporting
• Recovery
• During compilation process each phase may encounters errors and
has to deal with them.
• For this purpose the Error handler contains error handling routines.
Classification of Errors
Lexical analyzer
• It is the first phase of compiler.
• It is also known as linear analyzer or Scanner.
• It scans or reads the source program from left to right as a stream of
characters, and it groups these characters into a unit called “Tokens”.
OR
• It takes the source code program as a stream of characters and
broken them into tokens.
Lexical Analyzer
• Token:
•A sequence of characters having a collective meaning.
•Lexemes are said to be a sequence of characters
(alphanumeric) in a token.
•If the lexical analyzer finds a token invalid, it generates
an error.
•There are some predefined rules for every lexeme to
be identified as a valid token.
•These rules are defined by grammar rules, by means
of a pattern.
Lexical Analyzer (Token Cont.)
• A pattern explains what can be a token, and these
patterns are defined by means of regular expressions.
• In programming language, keywords, constants,
identifiers, strings, numbers, operators and
punctuations symbols can be considered as tokens
For example, in C language, the variable declaration line
int value = 100;
contains the tokens:
int (keyword), value (identifier), = (operator), 100 (constant) and ;
(symbol).
Lexical Analyzer (Token Cont.)
• The lexical analyzer works closely with the syntax
analyzer.
• It reads character streams from the source code,
checks for legal tokens, and passes the data to the
syntax analyzer when it demands.
Continue To
Next
Lecture

More Related Content

What's hot

Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionAhmed Raza
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design IntroductionRicha Sharma
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compileradilmehmood93
 
Spr ch-05-compilers
Spr ch-05-compilersSpr ch-05-compilers
Spr ch-05-compilersVasim Pathan
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilersVairavel C
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Bhavin Darji
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignAkhil Kaushik
 
Compilers in computer programming
Compilers in computer programmingCompilers in computer programming
Compilers in computer programmingChetan Pandey
 
Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler designJanani Parthiban
 
C and its errors
C and its errorsC and its errors
C and its errorsJunaid Raja
 

What's hot (20)

phases of a compiler
 phases of a compiler phases of a compiler
phases of a compiler
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Compiler construction
Compiler constructionCompiler construction
Compiler construction
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Compiler design
Compiler designCompiler design
Compiler design
 
Compilers
CompilersCompilers
Compilers
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
 
Spr ch-05-compilers
Spr ch-05-compilersSpr ch-05-compilers
Spr ch-05-compilers
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilers
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
Compiler1
Compiler1Compiler1
Compiler1
 
C programming
C programmingC programming
C programming
 
Lecture1 introduction compilers
Lecture1 introduction compilersLecture1 introduction compilers
Lecture1 introduction compilers
 
Compilers in computer programming
Compilers in computer programmingCompilers in computer programming
Compilers in computer programming
 
Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler design
 
C and its errors
C and its errorsC and its errors
C and its errors
 

Similar to Compiler lecture 04

COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxCOMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxRossy719186
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.pptsivaganesh293
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.pptsivaganesh293
 
Principles of Compiler Design - Introduction
Principles of Compiler Design - IntroductionPrinciples of Compiler Design - Introduction
Principles of Compiler Design - Introductionsheelarajasekar205
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptApoorv Diwan
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptxssuser3b4934
 
System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation filejithujithin657
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionSarmad Ali
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilersvijaya603274
 
Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler DesignMarimuthu M
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overviewamudha arul
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & RecoveryAkhil Kaushik
 
role of lexical anaysis
role of lexical anaysisrole of lexical anaysis
role of lexical anaysisSudhaa Ravi
 

Similar to Compiler lecture 04 (20)

1._Introduction_.pptx
1._Introduction_.pptx1._Introduction_.pptx
1._Introduction_.pptx
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxCOMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptx
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Principles of Compiler Design - Introduction
Principles of Compiler Design - IntroductionPrinciples of Compiler Design - Introduction
Principles of Compiler Design - Introduction
 
Lexical Analysis.pdf
Lexical Analysis.pdfLexical Analysis.pdf
Lexical Analysis.pdf
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation file
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
1 compiler outline
1 compiler outline1 compiler outline
1 compiler outline
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
 
Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler Design
 
11700220036.pdf
11700220036.pdf11700220036.pdf
11700220036.pdf
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
role of lexical anaysis
role of lexical anaysisrole of lexical anaysis
role of lexical anaysis
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
Compiler lecture 07
Compiler lecture 07Compiler lecture 07
Compiler lecture 07
 

More from University of Chitral (13)

Compiler lecture 06
Compiler lecture 06Compiler lecture 06
Compiler lecture 06
 
Compiler lecture 05
Compiler lecture 05Compiler lecture 05
Compiler lecture 05
 
Oop lecture 06
Oop lecture 06Oop lecture 06
Oop lecture 06
 
Oop lecture 05
Oop lecture 05Oop lecture 05
Oop lecture 05
 
OOP lecture 04
OOP  lecture 04OOP  lecture 04
OOP lecture 04
 
Compiler lecture 05
Compiler lecture 05Compiler lecture 05
Compiler lecture 05
 
Compiler lecture 04
Compiler lecture 04Compiler lecture 04
Compiler lecture 04
 
Compiler lecture 01
Compiler lecture 01Compiler lecture 01
Compiler lecture 01
 
Compiler lecture 02
Compiler lecture 02Compiler lecture 02
Compiler lecture 02
 
O op lecture 04
O op lecture 04O op lecture 04
O op lecture 04
 
Oop lecture 03
Oop lecture 03Oop lecture 03
Oop lecture 03
 
Oop lecture 02
Oop lecture 02Oop lecture 02
Oop lecture 02
 
Oop lecture 01
Oop lecture 01Oop lecture 01
Oop lecture 01
 

Recently uploaded

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 

Compiler lecture 04

  • 1. Compiler Construction By Noor wali khan UOCH Continue from Previous Lecture
  • 2. Error Handler • An error is an abnormal condition in source program, which either stope the compilation or generate undesired results. • A compiler must not stop at each error. • It must somehow handle the error, so that compilation proceeds up to the end of the program. • At the end a list of errors messages is provided to the user. • This is the job of the error handler, and also marks the place where the errors occur.
  • 3. Error Handler • Error handler contains a set of routines for handling error encountered in any phase of the compiler. • The basic tasks of the compiler are: • Detection • Reporting • Recovery • During compilation process each phase may encounters errors and has to deal with them. • For this purpose the Error handler contains error handling routines.
  • 5. Lexical analyzer • It is the first phase of compiler. • It is also known as linear analyzer or Scanner. • It scans or reads the source program from left to right as a stream of characters, and it groups these characters into a unit called “Tokens”. OR • It takes the source code program as a stream of characters and broken them into tokens.
  • 6. Lexical Analyzer • Token: •A sequence of characters having a collective meaning. •Lexemes are said to be a sequence of characters (alphanumeric) in a token. •If the lexical analyzer finds a token invalid, it generates an error. •There are some predefined rules for every lexeme to be identified as a valid token. •These rules are defined by grammar rules, by means of a pattern.
  • 7. Lexical Analyzer (Token Cont.) • A pattern explains what can be a token, and these patterns are defined by means of regular expressions. • In programming language, keywords, constants, identifiers, strings, numbers, operators and punctuations symbols can be considered as tokens For example, in C language, the variable declaration line int value = 100; contains the tokens: int (keyword), value (identifier), = (operator), 100 (constant) and ; (symbol).
  • 8. Lexical Analyzer (Token Cont.) • The lexical analyzer works closely with the syntax analyzer. • It reads character streams from the source code, checks for legal tokens, and passes the data to the syntax analyzer when it demands. Continue To Next Lecture