SlideShare a Scribd company logo
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

PPTX
Type checking in compiler design
PPTX
Error Recovery strategies and yacc | Compiler Design
PPT
Analysis of the source program
PPTX
Compiler lecture 03
PPTX
The analysis synthesis model of compilation
PPTX
Phases of a Compiler
PPT
Lexical analyzer
PPTX
phases of compiler-analysis phase
Type checking in compiler design
Error Recovery strategies and yacc | Compiler Design
Analysis of the source program
Compiler lecture 03
The analysis synthesis model of compilation
Phases of a Compiler
Lexical analyzer
phases of compiler-analysis phase

What's hot (20)

PPT
phases of a compiler
PPTX
Compiler Construction
PPT
Cpcs302 1
PDF
Compiler Design Introduction
PDF
Phases of Compiler
PPTX
Compiler construction
PPTX
Phases of compiler
PPTX
Compiler design
PPTX
PPT
what is compiler and five phases of compiler
PPSX
Spr ch-05-compilers
PPT
Passes of compilers
PPT
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
PPTX
Lexical Analysis - Compiler Design
PPT
Compiler1
PPTX
C programming
PDF
Lecture1 introduction compilers
PPTX
Compilers in computer programming
PPT
Principles of compiler design
PPTX
C and its errors
phases of a compiler
Compiler Construction
Cpcs302 1
Compiler Design Introduction
Phases of Compiler
Compiler construction
Phases of compiler
Compiler design
what is compiler and five phases of compiler
Spr ch-05-compilers
Passes of compilers
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Lexical Analysis - Compiler Design
Compiler1
C programming
Lecture1 introduction compilers
Compilers in computer programming
Principles of compiler design
C and its errors
Ad

Similar to Compiler lecture 04 (20)

PDF
An Introduction to the Compiler Designss
DOCX
Compiler Design
PDF
Assignment4
PDF
Lexical Analysis.pdf
PDF
11700220036.pdf
PPTX
Compiler Design.pptx
PDF
compiler.pdfljdvgepitju4io3elkhldhyreyio4uw
PPT
Unit1.ppt
PPTX
role of lexical anaysis
PDF
C compiler(final)
PPTX
compiler introduction vtu syllabus 1st chapter.pptx
PPT
SS & CD Module 3
PPT
Module 2
PPTX
Chapter 2.pptx compiler design lecture note
PPTX
Cd ch2 - lexical analysis
PDF
3a. Context Free Grammar.pdf
PPTX
1._Introduction_.pptx
PPTX
Lexical Analyser PPTs for Third Lease Computer Sc. and Engineering
PPT
Chapter-2-lexical-analyser and its property lecture note.ppt
PPTX
Plc part 2
An Introduction to the Compiler Designss
Compiler Design
Assignment4
Lexical Analysis.pdf
11700220036.pdf
Compiler Design.pptx
compiler.pdfljdvgepitju4io3elkhldhyreyio4uw
Unit1.ppt
role of lexical anaysis
C compiler(final)
compiler introduction vtu syllabus 1st chapter.pptx
SS & CD Module 3
Module 2
Chapter 2.pptx compiler design lecture note
Cd ch2 - lexical analysis
3a. Context Free Grammar.pdf
1._Introduction_.pptx
Lexical Analyser PPTs for Third Lease Computer Sc. and Engineering
Chapter-2-lexical-analyser and its property lecture note.ppt
Plc part 2
Ad

More from University of Chitral (14)

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

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
Basic Mud Logging Guide for educational purpose
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Institutional Correction lecture only . . .
PDF
01-Introduction-to-Information-Management.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Lesson notes of climatology university.
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Pharma ospi slides which help in ospi learning
Basic Mud Logging Guide for educational purpose
Supply Chain Operations Speaking Notes -ICLT Program
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Institutional Correction lecture only . . .
01-Introduction-to-Information-Management.pdf
human mycosis Human fungal infections are called human mycosis..pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Lesson notes of climatology university.
Microbial disease of the cardiovascular and lymphatic systems
Anesthesia in Laparoscopic Surgery in India
TR - Agricultural Crops Production NC III.pdf
PPH.pptx obstetrics and gynecology in nursing
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pre independence Education in Inndia.pdf
VCE English Exam - Section C Student Revision Booklet

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