SlideShare une entreprise Scribd logo
1  sur  23
Akhil Kaushik
Asstt. Prof., CE Deptt.,
TIT Bhiwani
Error Detection & Recovery
Error Handling
• It is an important feature of any compiler.
• A good compiler should be able to detect and report
errors.
• It should be able to modify input, when it finds an
error in lexical analysis phase.
• A more sophisticated compiler should be able to
correct the errors, by making guess of user
intentions.
Error Handling
• The most important feature of error handler is
correct and more centric error message.
• It should following properties:-
– Reporting errors in original source program, rather than
intermediate or final code.
– Error message shouldn’t be complicated.
– Error message shouldn’t be duplicated.
– Error message should localize the problem.
Sources of Error
• Algorithmic Errors:-
– The algorithm used to meet the design may be
inadequate or incorrect.
• Coding Errors:-
– The programmer may introduce syntax or logical errors
in implementing the algorithms.
Sources of Error
• Lexical Phase:-
– wrongly formed identifiers (or tokens).
– Some character used which is undefined in PL.
– Addition of an extra character.
– Removal of a character that should be present.
– Replacement of a character with an incorrect characters.
– Transposition of 2 characters.
Sources of Error
• Lexical Phase:-
– Best way to handle a lexical error is to find the closest
character sequence that does match a pattern (takes
long time & unpractical)
– Another way is to feed lexical analyzer – a list of
legitimate token available to the error recovery routines.
– Or generate an error.
Sources of Error
• Syntactic:-
– Comma instead of a semi-colon.
– Misspelled keywords, operators.
– Two expressions not connected by operator.
– Null expression between parenthesis
– Unbalanced parenthesis
– Handle is absent
• Usually, panic mode or phrase-level recovery is
used.
Sources of Error
• Semantic:
– Declaration and scope errors like use of undeclared
or multi-declared identifiers, type mismatch, etc.
– In case of undeclared name, make an entry in the
Symbol table & its attributes.
– Set a flag in ST that it was done due to an error
rather than declaration.
Sources of Error
• Logical:
– Syntax is correct, but wrong logic applied to programmer.
– Most difficult to recover.
– Hard to detect by compiler.
Goals of Error Handler
• Detect errors quickly and produce meaningful
diagnostic.
• Detect subsequent errors after an error correction.
• It shouldn’t slow down compilation.
Goals of Error Handler
Program submitted to a compiler often have errors of
various kinds:-
• So, good compiler should be able to detect as many
errors as possible in various ways.
• Even in the presence of errors ,the compiler should
scan the program and try to compile all of it.(error
recovery).
Goals of Error Handler
• When the scanner or parser finds an error and
cannot proceed ?
• Then, the compiler must modify the input so that the
correct portions of the program can be pieced
together and successfully processed in the syntax
analysis phase.
CORRECTING COMPILER
• These compilers does the job of error recovery not
only from the compiler point of view but also from
the programmers point of view.
• Ex:PL/C
• But, error recovery should not lead to misleading or
spurious error messages elsewhere (error
propagation).
Run-Time Errors
• Indication of run time errors is another neglected
area in compiler design.
• Because, code generated to monitor these
violations increases the target program size, which
leads to slow execution.
• So these checks are included as “debugging
options”.
Error Recovery Strategies
There are four common error-recovery strategies that
can be implemented in the parser to deal with errors
in the code:-
• Panic mode recovery
• Phrase-level recovery
• Error productions
• Global correction
Error Recovery Strategies
Panic Mode Recovery:-
• Once an error is found, the parser intends to find
designated set of synchronizing tokens (delimiters,
semicolon or } ) by discarding input symbols one at
a time.
• When parser finds an error in the statement, it
ignores the rest of the statement by not processing
the input.
Error Recovery Strategies
Panic Mode Recovery:-
• This is the easiest way of error-recovery.
• It prevents the parser from developing infinite loops.
• Ex: a=b + c // no semi-colon
• d=e + f ;
• The compiler will discard all subsequent tokens till a
semi-colon is encountered.
Error Recovery Strategies
Phrase-level Recovery:-
• Perform local correction on the remaining input i.e.
localize the problem and then do error recovery.
• It’s a fast way for error recovery.
• Ex: A typical local correction is to replace a comma
by a semicolon.
• Ex: Delete an extraneous semicolon and Insert a
missing semicolon.
Error Recovery Strategies
Error Productions:-
• Add rules to grammar that describe the erroneous
syntax.
• It may resolve many, but not all potential errors.
• Good idea about common errors is found & their
appropriate solution is stored.
• These productions detect the anticipated errors
during parsing.
Error Recovery Strategies
Error Productions:-
• Ex: E→ +E | -E | *E | /E
• Here, the last two are error situations.
• Now, we change the grammar as:
E→ +E | -E | *A | /A
A→ E
• Hence, once it encounters *A, it sends an error
message asking the user if he is sure he wants to
use a unary “*”.
Error Recovery Strategies
Global Correction:-
• Compiler to make as few changes as possible in
processing an incorrect input string.
• Given an incorrect input string x and grammar g,
algorithms will find a parse tree for a related string y,
such that the number of insertions, deletions, and
changes of tokens required to transform x into y is
as small as possible.
Error Recovery Strategies
Global Correction:-
• It does the global analysis to find the errors.
• Expensive method & not practically used.
• Costly in terms of time & space.
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
CONTACT ME AT:
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
THANK YOU !!!

Contenu connexe

Tendances

Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design) Tasif Tanzim
 
Design issues for the layers
Design issues for the layersDesign issues for the layers
Design issues for the layersjayaprakash
 
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dhrumil Panchal
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler designKuppusamy P
 
The role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designThe role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designSadia Akter
 
Presentation on cyclic redundancy check (crc)
Presentation on cyclic redundancy check (crc)Presentation on cyclic redundancy check (crc)
Presentation on cyclic redundancy check (crc)Sudhanshu Srivastava
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler designSudip Singh
 
Algorithmic problem solving
Algorithmic problem solvingAlgorithmic problem solving
Algorithmic problem solvingPrabhakaran V M
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
 
Compiler Design
Compiler DesignCompiler Design
Compiler DesignMir Majid
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithmBushra M
 
Algorithm and Flowcharts
Algorithm and FlowchartsAlgorithm and Flowcharts
Algorithm and FlowchartsSURBHI SAROHA
 
Compiler design error handling
Compiler design error handlingCompiler design error handling
Compiler design error handlingRohitK71
 

Tendances (20)

Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
Design issues for the layers
Design issues for the layersDesign issues for the layers
Design issues for the layers
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
The role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designThe role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler design
 
Presentation on cyclic redundancy check (crc)
Presentation on cyclic redundancy check (crc)Presentation on cyclic redundancy check (crc)
Presentation on cyclic redundancy check (crc)
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler design
 
Unit 3 sp assembler
Unit 3 sp assemblerUnit 3 sp assembler
Unit 3 sp assembler
 
Algorithmic problem solving
Algorithmic problem solvingAlgorithmic problem solving
Algorithmic problem solving
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
White box ppt
White box pptWhite box ppt
White box ppt
 
Code generation
Code generationCode generation
Code generation
 
Types of Compilers
Types of CompilersTypes of Compilers
Types of Compilers
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithm
 
Algorithm and Flowcharts
Algorithm and FlowchartsAlgorithm and Flowcharts
Algorithm and Flowcharts
 
Compiler design error handling
Compiler design error handlingCompiler design error handling
Compiler design error handling
 

Similaire à Error Detection & Recovery Strategies in Compilers

Error Detection & Recovery.pptx
Error Detection & Recovery.pptxError Detection & Recovery.pptx
Error Detection & Recovery.pptxMohibKhan79
 
Error Recovery strategies and yacc | Compiler Design
Error Recovery strategies and yacc | Compiler DesignError Recovery strategies and yacc | Compiler Design
Error Recovery strategies and yacc | Compiler DesignShamsul Huda
 
System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation filejithujithin657
 
UNIT-2-compiler design
UNIT-2-compiler designUNIT-2-compiler design
UNIT-2-compiler designkamaless4
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionSarmad Ali
 
Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler DesignMarimuthu M
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing TechniquesAppili Vamsi Krishna
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptxssuser3b4934
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem slovingMani Kandan
 
Unit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and FlowchartUnit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and FlowchartBom Khati
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overviewamudha arul
 
Computer programing 111 lecture 2
Computer programing 111 lecture 2Computer programing 111 lecture 2
Computer programing 111 lecture 2ITNet
 

Similaire à Error Detection & Recovery Strategies in Compilers (20)

Error Detection & Recovery.pptx
Error Detection & Recovery.pptxError Detection & Recovery.pptx
Error Detection & Recovery.pptx
 
Error Recovery strategies and yacc | Compiler Design
Error Recovery strategies and yacc | Compiler DesignError Recovery strategies and yacc | Compiler Design
Error Recovery strategies and yacc | Compiler Design
 
System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation file
 
chapter4 end.pptx
chapter4 end.pptxchapter4 end.pptx
chapter4 end.pptx
 
UNIT-2-compiler design
UNIT-2-compiler designUNIT-2-compiler design
UNIT-2-compiler design
 
Error Handling.pptx
Error Handling.pptxError Handling.pptx
Error Handling.pptx
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler Design
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
 
Compiler lecture 04
Compiler lecture 04Compiler lecture 04
Compiler lecture 04
 
Compiler lecture 04
Compiler lecture 04Compiler lecture 04
Compiler lecture 04
 
Unit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and FlowchartUnit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and Flowchart
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
Computer programing 111 lecture 2
Computer programing 111 lecture 2Computer programing 111 lecture 2
Computer programing 111 lecture 2
 
Cp 111 lecture 2
Cp 111 lecture 2Cp 111 lecture 2
Cp 111 lecture 2
 
Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
 

Plus de Akhil Kaushik

Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationAkhil Kaushik
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free GrammarAkhil Kaushik
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer ImplementationAkhil Kaushik
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignAkhil Kaushik
 
File Handling Python
File Handling PythonFile Handling Python
File Handling PythonAkhil Kaushik
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity CalculationAkhil Kaushik
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsAkhil Kaushik
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & LoopsAkhil Kaushik
 
Basic programs in Python
Basic programs in PythonBasic programs in Python
Basic programs in PythonAkhil Kaushik
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python ProgrammingAkhil Kaushik
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in CompilerAkhil Kaushik
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction toolsAkhil Kaushik
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to CompilersAkhil Kaushik
 

Plus de Akhil Kaushik (20)

Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free Grammar
 
Symbol Table
Symbol TableSymbol Table
Symbol Table
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer Implementation
 
NFA & DFA
NFA & DFANFA & DFA
NFA & DFA
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & Algorithms
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
 
Basic programs in Python
Basic programs in PythonBasic programs in Python
Basic programs in Python
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 

Dernier

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
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
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 

Dernier (20)

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
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
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 

Error Detection & Recovery Strategies in Compilers

  • 1. Akhil Kaushik Asstt. Prof., CE Deptt., TIT Bhiwani Error Detection & Recovery
  • 2. Error Handling • It is an important feature of any compiler. • A good compiler should be able to detect and report errors. • It should be able to modify input, when it finds an error in lexical analysis phase. • A more sophisticated compiler should be able to correct the errors, by making guess of user intentions.
  • 3. Error Handling • The most important feature of error handler is correct and more centric error message. • It should following properties:- – Reporting errors in original source program, rather than intermediate or final code. – Error message shouldn’t be complicated. – Error message shouldn’t be duplicated. – Error message should localize the problem.
  • 4. Sources of Error • Algorithmic Errors:- – The algorithm used to meet the design may be inadequate or incorrect. • Coding Errors:- – The programmer may introduce syntax or logical errors in implementing the algorithms.
  • 5. Sources of Error • Lexical Phase:- – wrongly formed identifiers (or tokens). – Some character used which is undefined in PL. – Addition of an extra character. – Removal of a character that should be present. – Replacement of a character with an incorrect characters. – Transposition of 2 characters.
  • 6. Sources of Error • Lexical Phase:- – Best way to handle a lexical error is to find the closest character sequence that does match a pattern (takes long time & unpractical) – Another way is to feed lexical analyzer – a list of legitimate token available to the error recovery routines. – Or generate an error.
  • 7. Sources of Error • Syntactic:- – Comma instead of a semi-colon. – Misspelled keywords, operators. – Two expressions not connected by operator. – Null expression between parenthesis – Unbalanced parenthesis – Handle is absent • Usually, panic mode or phrase-level recovery is used.
  • 8. Sources of Error • Semantic: – Declaration and scope errors like use of undeclared or multi-declared identifiers, type mismatch, etc. – In case of undeclared name, make an entry in the Symbol table & its attributes. – Set a flag in ST that it was done due to an error rather than declaration.
  • 9. Sources of Error • Logical: – Syntax is correct, but wrong logic applied to programmer. – Most difficult to recover. – Hard to detect by compiler.
  • 10. Goals of Error Handler • Detect errors quickly and produce meaningful diagnostic. • Detect subsequent errors after an error correction. • It shouldn’t slow down compilation.
  • 11. Goals of Error Handler Program submitted to a compiler often have errors of various kinds:- • So, good compiler should be able to detect as many errors as possible in various ways. • Even in the presence of errors ,the compiler should scan the program and try to compile all of it.(error recovery).
  • 12. Goals of Error Handler • When the scanner or parser finds an error and cannot proceed ? • Then, the compiler must modify the input so that the correct portions of the program can be pieced together and successfully processed in the syntax analysis phase.
  • 13. CORRECTING COMPILER • These compilers does the job of error recovery not only from the compiler point of view but also from the programmers point of view. • Ex:PL/C • But, error recovery should not lead to misleading or spurious error messages elsewhere (error propagation).
  • 14. Run-Time Errors • Indication of run time errors is another neglected area in compiler design. • Because, code generated to monitor these violations increases the target program size, which leads to slow execution. • So these checks are included as “debugging options”.
  • 15. Error Recovery Strategies There are four common error-recovery strategies that can be implemented in the parser to deal with errors in the code:- • Panic mode recovery • Phrase-level recovery • Error productions • Global correction
  • 16. Error Recovery Strategies Panic Mode Recovery:- • Once an error is found, the parser intends to find designated set of synchronizing tokens (delimiters, semicolon or } ) by discarding input symbols one at a time. • When parser finds an error in the statement, it ignores the rest of the statement by not processing the input.
  • 17. Error Recovery Strategies Panic Mode Recovery:- • This is the easiest way of error-recovery. • It prevents the parser from developing infinite loops. • Ex: a=b + c // no semi-colon • d=e + f ; • The compiler will discard all subsequent tokens till a semi-colon is encountered.
  • 18. Error Recovery Strategies Phrase-level Recovery:- • Perform local correction on the remaining input i.e. localize the problem and then do error recovery. • It’s a fast way for error recovery. • Ex: A typical local correction is to replace a comma by a semicolon. • Ex: Delete an extraneous semicolon and Insert a missing semicolon.
  • 19. Error Recovery Strategies Error Productions:- • Add rules to grammar that describe the erroneous syntax. • It may resolve many, but not all potential errors. • Good idea about common errors is found & their appropriate solution is stored. • These productions detect the anticipated errors during parsing.
  • 20. Error Recovery Strategies Error Productions:- • Ex: E→ +E | -E | *E | /E • Here, the last two are error situations. • Now, we change the grammar as: E→ +E | -E | *A | /A A→ E • Hence, once it encounters *A, it sends an error message asking the user if he is sure he wants to use a unary “*”.
  • 21. Error Recovery Strategies Global Correction:- • Compiler to make as few changes as possible in processing an incorrect input string. • Given an incorrect input string x and grammar g, algorithms will find a parse tree for a related string y, such that the number of insertions, deletions, and changes of tokens required to transform x into y is as small as possible.
  • 22. Error Recovery Strategies Global Correction:- • It does the global analysis to find the errors. • Expensive method & not practically used. • Costly in terms of time & space.
  • 23. Akhil Kaushik akhilkaushik05@gmail.com 9416910303 CONTACT ME AT: Akhil Kaushik akhilkaushik05@gmail.com 9416910303 THANK YOU !!!