SlideShare a Scribd company logo
Error Handling in Compiler Design
The tasks of the Error Handling process are to detect each error, report it to the user,
and then make some recovery strategy and implement them to handle the error.
During this whole process processing time of the program should not be slow.
Functions of Error Handler:
 Error Detection
 Error Report
 Error Recovery
Error handler=Error Detection+Error Report+Error Recovery.
An Error is the blank entries in the symbol table.
Errors in the program should be detected and reported by the parser. Whenever an
error occurs, the parser can handle it and continue to parse the rest of the input.
Although the parser is mostly responsible for checking for errors, errors may occur at
various stages of the compilation process.
So, there are many types of errors and some of these are:
Types or Sources of Error – There are three types of error: logic, run-time and
compile-time error:
Logic errors occur when programs operate incorrectly but do not terminate
abnormally (or crash). Unexpected or undesired outputs or other behaviour may result
from a logic error, even if it is not immediately recognized as such.
1. A run-time error is an error that takes place during the execution of a program and usually
happens because of adverse system parameters or invalid input data. The lack of sufficient
memory to run an application or a memory conflict with another program and logical error is
an example of this. Logic errors occur when executed code does not produce the expected
result. Logic errors are best handled by meticulous program debugging.
2. Compile-time errors rise at compile-time, before the execution of the program. Syntax error
or missing file reference that prevents the program from successfully compiling is an
example of this.
Classification of Compile-time error –
1. Lexical : This includes misspellings of identifiers, keywords or operators
2. Syntactical : a missing semicolon or unbalanced parenthesis
3. Semantical : incompatible value assignment or type mismatches between operator and
operand
4. Logical : code not reachable, infinite loop.
Finding error or reporting an error – Viable-prefix is the property of a parser that
allows early detection of syntax errors.
 Goal detection of an error as soon as possible without further consuming unnecessary input
 How: detect an error as soon as the prefix of the input does not match a prefix of any string
in the language.
Example: for(;), this will report an error as for having two semicolons inside braces.
Error Recovery –
The basic requirement for the compiler is to simply stop and issue a message, and
cease compilation. There are some common recovery methods that are as follows.
We already discuss the errors. Now, let’s try to understand the recovery of errors in
every phase of the compiler.
1. Panic mode recovery :
This is the easiest way of error-recovery and also, it prevents the parser from
developing infinite loops while recovering error. The parser discards the input symbol
one at a time until one of the designated (like end, semicolon) set of synchronizing
tokens (are typically the statement or expression terminators) is found. This is
adequate when the presence of multiple errors in the same statement is rare. Example:
Consider the erroneous expression- (1 + + 2) + 3. Panic-mode recovery: Skip ahead to
the next integer and then continue. Bison: use the special terminal error to describe
how much input to skip.
E->int|E+E|(E)|error int|(error)
2. Phase level recovery :
When an error is discovered, the parser performs local correction on the remaining
input. If a parser encounters an error, it makes the necessary corrections on the
remaining input so that the parser can continue to parse the rest of the statement. You
can correct the error by deleting extra semicolons, replacing commas with semicolons,
or reintroducing missing semicolons. To prevent going in an infinite loop during the
correction, utmost care should be taken. Whenever any prefix is found in the
remaining input, it is replaced with some string. In this way, the parser can continue to
operate on its execution.
3. Error productions :
The use of the error production method can be incorporated if the user is aware of
common mistakes that are encountered in grammar in conjunction with errors that
produce erroneous constructs. When this is used, error messages can be generated
during the parsing process, and the parsing can continue. Example: write 5x instead of
5*x
4. Global correction :
In order to recover from erroneous input, the parser analyzes the whole program and
tries to find the closest match for it, which is error-free. The closest match is one that
does not do many insertions, deletions, and changes of tokens. This method is not
practical due to its high time and space complexity.
Advantages of Error Handling in Compiler Design:
1.Robustness: Mistake dealing with improves the strength of the compiler by
permitting it to deal with and recuperate from different sorts of blunders smoothly.
This guarantees that even within the sight of blunders, the compiler can keep handling
the information program and give significant mistake messages.
2.Error location: By consolidating blunder taking care of components, a compiler
can distinguish and recognize mistakes in the source code. This incorporates syntactic
mistakes, semantic blunders, type blunders, and other potential issues that might make
the program act startlingly or produce erroneous result.
3.Error revealing: Compiler mistake taking care of works with viable blunder
answering to the client or software engineer. It creates engaging blunder messages
that assist developers with understanding the nature and area of the mistake,
empowering them to effectively fix the issues. Clear and exact mistake messages save
designers significant time in the troubleshooting system.
4.Error recuperation: Mistake dealing with permits the compiler to recuperate from
blunders and proceed with the aggregation cycle whenever the situation allows. This
is accomplished through different methods like blunder adjustment, mistake
synchronization, and resynchronization. The compiler endeavors to redress the
blunders and continues with assemblage, keeping the whole interaction from being
ended unexpectedly.
5.Incremental gathering: Mistake taking care of empowers gradual aggregation,
where a compiler can order and execute right partitions of the program regardless of
whether different segments contain blunders. This element is especially helpful for
enormous scope projects, as it permits engineers to test and investigate explicit
modules without recompiling the whole codebase.
6.Productivity improvement: With legitimate mistake taking care of, the compiler
diminishes the time and exertion spent on troubleshooting and blunder fixing. By
giving exact mistake messages and supporting blunder recuperation, it assists
programmers with rapidly recognizing and resolve issues, prompting further
developed efficiency and quicker advancement cycles.
7.Language turn of events: Mistake taking care of is a fundamental part of language
plan and advancement. By consolidating mistake dealing with systems in the compiler,
language fashioners can characterize the normal blunder conduct and authorize
explicit standards and imperatives. This adds to the general dependability and
consistency of the language, guaranteeing that developers stick to the expected
utilization designs.
Disadvantages of error handling in compiler design:
Increased complexity: Error handling in compiler design can significantly increase
the complexity of the compiler. This can make the compiler more challenging to
develop, test, and maintain. The more complex the error handling mechanism is, the
more difficult it becomes to ensure that it is working correctly and to find and fix
errors.
Reduced performance: Error handling in compiler design can also impact the
performance of the compiler. This is especially true if the error handling mechanism
is time-consuming and computationally intensive. As a result, the compiler may take
longer to compile programs and may require more resources to operate.
Increased development time: Developing an effective error handling mechanism can
be a time-consuming process. This is because it requires significant testing and
debugging to ensure that it works as intended. This can slow down the development
process and result in longer development times.
Difficulty in error detection: While error handling is designed to identify and handle
errors in the source code, it can also make it more difficult to detect errors. This is
because the error handling mechanism may mask some errors, making it harder to
identify them. Additionally, if the error handling mechanism is not working correctly,
it may fail to detect errors altogether.
Next related article – Error detection and Recovery in Compiler
Here's a complete roadmap for you to become a developer: Learn DSA -> Master
Frontend/Backend/Full Stack -> Build Projects -> Keep Applying to Jobs
And why go anywhere else when our DSA to Development: Coding Guide helps you
do this in a single program! Apply now to our DSA to Development Program and our
counsellors will connect with you for further guidance & support.
Difference between Recursive
Predictive Descent Parser and Non-
Recursive Predictive Descent
Parser



Prerequisite – Recursive Descent Parser
1. Recursive Predictive Descent Parser :
Recursive Descent Parser is a top-down method of syntax analysis in which a set of
recursive procedures is used to process input. One procedure is associated with each
non-terminal of a grammar. Here we consider a simple form of recursive descent
parsing called Predictive Recursive Descent Parser, in which look-ahead symbol
unambiguously determines flow of control through procedure body for each non-
terminal. The sequence of procedure calls during analysis of an input string implicitly
defines a parse tree for input and can be used to build an explicit parse tree, if desired.
In recursive descent parsing, parser may have more than one production to choose
from for a single instance of input there concept of backtracking comes into play.
Back-tracking –
It means, if one derivation of a production fails, syntax analyzer restarts process using
different rules of same production. This technique may process input string more than
once to determine right production.Top- down parser start from root node (start
symbol) and match input string against production rules to replace them (if matched).
To understand this, take following example of CFG :
S -> aAb | aBb
A -> cx | dx
B -> xe
For an input string – read, a top-down parser, will behave like this.
It will start with S from production rules and will match its yield to left-most letter of
input, i.e. ‘a’. The very production of S (S -> aAb) matches with it. So top-down
parser advances to next input letter (i.e., ‘d’). The parser tries to expand non-terminal
‘A’ and checks its production from left (A -> cx). It does not match with next input
symbol. So top-down parser backtracks to obtain next production rule of A, (A ->
dx).
Now parser matches all input letters in an ordered manner. The string is accepted.
2. Non-Recursive Predictive Descent Parser :
A form of recursive-descent parsing that does not require any back-tracking is known
as predictive parsing. It is also called as LL(1) parsing table technique since we would
be building a table for string to be parsed. It has capability to predict which
production is to be used to replace input string. To accomplish its tasks, predictive
parser uses a look-ahead pointer, which points to next input symbols. To make parser
back-tracking free, predictive parser puts some constraints on grammar and accepts
only a class of grammar known as LL(k) grammar.
Predictive parsing uses a stack and a parsing table to parse input and generate a parse
tree. Both stack and input contains an end symbol $ to denote that stack is empty and
input is consumed. The parser refers to parsing table to take any decision on input and
stack element combination. There might be instances where there is no production
matching input string, making parsing procedure to fail.
Difference between Recursive Predictive Descent Parser and Non-Recursive
Predictive Descent Parser :
Recursive Predictive Descent Parser Non-Recursive Predictive Descent Parser
It is a technique which may or
may not require backtracking
process.
It is a technique that does not
require any kind of backtracking.
It uses procedures for every
non-terminal entity to parse
strings.
It finds out productions to use by
replacing input string.
It is a type of top-down parsing
built from a set of mutually
recursive procedures where each
procedure implements one of non-
terminal s of grammar.
It is a type of top-down approach,
which is also a type of recursive
parsing that does not uses technique
of backtracking.
It contains several small The predictive parser uses a look
Recursive Predictive Descent Parser Non-Recursive Predictive Descent Parser
functions one for each non-
terminals in grammar.
ahead pointer which points to next
input symbols to make it parser back
tracking free, predictive parser
puts some constraints on grammar.
It accepts all kinds of
grammars.
It accepts only a class of grammar
known as LL(k) grammar.
Ad

More Related Content

What's hot (20)

C program to write c program without using main function
C program to write c program without using main functionC program to write c program without using main function
C program to write c program without using main function
Rumman Ansari
 
Multiprocessor
MultiprocessorMultiprocessor
Multiprocessor
Kamal Acharya
 
python conditional statement.pptx
python conditional statement.pptxpython conditional statement.pptx
python conditional statement.pptx
Dolchandra
 
Principal of objected oriented programming
Principal of objected oriented programming Principal of objected oriented programming
Principal of objected oriented programming
Rokonuzzaman Rony
 
File system vs DBMS
File system vs DBMSFile system vs DBMS
File system vs DBMS
BHARATH KUMAR
 
LAN (Local Area Network)
LAN (Local Area Network)LAN (Local Area Network)
LAN (Local Area Network)
Muhammad Ridwanul Hoque
 
Solution manual for database systems a practical approach to design implement...
Solution manual for database systems a practical approach to design implement...Solution manual for database systems a practical approach to design implement...
Solution manual for database systems a practical approach to design implement...
zammok
 
pipelining
pipeliningpipelining
pipelining
sudhir saurav
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
smruti sarangi
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
sunilchute1
 
2nd puc computer science chapter 3 data structures 1
2nd puc computer science chapter 3 data structures 12nd puc computer science chapter 3 data structures 1
2nd puc computer science chapter 3 data structures 1
Aahwini Esware gowda
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
Ashim Lamichhane
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
Sowmya Jyothi
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
ssuserd2f031
 
Structure of the page table
Structure of the page tableStructure of the page table
Structure of the page table
duvvuru madhuri
 
Storage classes in c++
Storage classes in c++Storage classes in c++
Storage classes in c++
Jaspal Singh
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
Rajab Ali
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
Ashok Raj
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
Prof. Dr. K. Adisesha
 
Hypertext,hypermedia and multimedia
Hypertext,hypermedia and multimediaHypertext,hypermedia and multimedia
Hypertext,hypermedia and multimedia
gaflores2
 
C program to write c program without using main function
C program to write c program without using main functionC program to write c program without using main function
C program to write c program without using main function
Rumman Ansari
 
python conditional statement.pptx
python conditional statement.pptxpython conditional statement.pptx
python conditional statement.pptx
Dolchandra
 
Principal of objected oriented programming
Principal of objected oriented programming Principal of objected oriented programming
Principal of objected oriented programming
Rokonuzzaman Rony
 
Solution manual for database systems a practical approach to design implement...
Solution manual for database systems a practical approach to design implement...Solution manual for database systems a practical approach to design implement...
Solution manual for database systems a practical approach to design implement...
zammok
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
smruti sarangi
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
sunilchute1
 
2nd puc computer science chapter 3 data structures 1
2nd puc computer science chapter 3 data structures 12nd puc computer science chapter 3 data structures 1
2nd puc computer science chapter 3 data structures 1
Aahwini Esware gowda
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
Sowmya Jyothi
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
ssuserd2f031
 
Structure of the page table
Structure of the page tableStructure of the page table
Structure of the page table
duvvuru madhuri
 
Storage classes in c++
Storage classes in c++Storage classes in c++
Storage classes in c++
Jaspal Singh
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
Rajab Ali
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
Ashok Raj
 
Hypertext,hypermedia and multimedia
Hypertext,hypermedia and multimediaHypertext,hypermedia and multimedia
Hypertext,hypermedia and multimedia
gaflores2
 

Similar to Error Handling in Compiler Design.doctyp (20)

UNIT-2-compiler design
UNIT-2-compiler designUNIT-2-compiler design
UNIT-2-compiler design
kamaless4
 
1_Introduction to C programming - Copy.ppt
1_Introduction to C programming - Copy.ppt1_Introduction to C programming - Copy.ppt
1_Introduction to C programming - Copy.ppt
AnnMuthoni14
 
Error Correction Techniques
Error Correction TechniquesError Correction Techniques
Error Correction Techniques
Kelly Bauer
 
Software Bugs A Software Architect Point Of View
Software Bugs    A Software Architect Point Of ViewSoftware Bugs    A Software Architect Point Of View
Software Bugs A Software Architect Point Of View
Shahzad
 
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdfVISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
NALANDACSCCENTRE
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
Prof. Erwin Globio
 
Stnotes doc 5
Stnotes doc 5Stnotes doc 5
Stnotes doc 5
Alok Jain
 
PROBLEM SOLVING
PROBLEM SOLVINGPROBLEM SOLVING
PROBLEM SOLVING
shahzadebaujiti
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)
TejaswiB4
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
Akhil Kaushik
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
A. S. M. Shafi
 
grade 10 2023.pptx
grade 10 2023.pptxgrade 10 2023.pptx
grade 10 2023.pptx
RaymartHerera
 
Bug Life Cycle in Software Testing: Understanding the Journey from Detection ...
Bug Life Cycle in Software Testing: Understanding the Journey from Detection ...Bug Life Cycle in Software Testing: Understanding the Journey from Detection ...
Bug Life Cycle in Software Testing: Understanding the Journey from Detection ...
Shubham Joshi
 
Error Detection & Recovery.pptx
Error Detection & Recovery.pptxError Detection & Recovery.pptx
Error Detection & Recovery.pptx
MohibKhan79
 
Error detection recovery
Error detection recoveryError detection recovery
Error detection recovery
Tech_MX
 
(D 15 180770107240)
(D 15 180770107240)(D 15 180770107240)
(D 15 180770107240)
RaviModi37
 
A Survey Of Systems For Detecting Serial Run-Time Errors
A Survey Of Systems For Detecting Serial Run-Time ErrorsA Survey Of Systems For Detecting Serial Run-Time Errors
A Survey Of Systems For Detecting Serial Run-Time Errors
Lisa Graves
 
Compiler design error handling
Compiler design error handlingCompiler design error handling
Compiler design error handling
RohitK71
 
Computer programing 111 lecture 2
Computer programing 111 lecture 2Computer programing 111 lecture 2
Computer programing 111 lecture 2
ITNet
 
Cp 111 lecture 2
Cp 111 lecture 2Cp 111 lecture 2
Cp 111 lecture 2
HafidhyMasoud
 
UNIT-2-compiler design
UNIT-2-compiler designUNIT-2-compiler design
UNIT-2-compiler design
kamaless4
 
1_Introduction to C programming - Copy.ppt
1_Introduction to C programming - Copy.ppt1_Introduction to C programming - Copy.ppt
1_Introduction to C programming - Copy.ppt
AnnMuthoni14
 
Error Correction Techniques
Error Correction TechniquesError Correction Techniques
Error Correction Techniques
Kelly Bauer
 
Software Bugs A Software Architect Point Of View
Software Bugs    A Software Architect Point Of ViewSoftware Bugs    A Software Architect Point Of View
Software Bugs A Software Architect Point Of View
Shahzad
 
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdfVISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
NALANDACSCCENTRE
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
Prof. Erwin Globio
 
Stnotes doc 5
Stnotes doc 5Stnotes doc 5
Stnotes doc 5
Alok Jain
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)
TejaswiB4
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
Akhil Kaushik
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
A. S. M. Shafi
 
Bug Life Cycle in Software Testing: Understanding the Journey from Detection ...
Bug Life Cycle in Software Testing: Understanding the Journey from Detection ...Bug Life Cycle in Software Testing: Understanding the Journey from Detection ...
Bug Life Cycle in Software Testing: Understanding the Journey from Detection ...
Shubham Joshi
 
Error Detection & Recovery.pptx
Error Detection & Recovery.pptxError Detection & Recovery.pptx
Error Detection & Recovery.pptx
MohibKhan79
 
Error detection recovery
Error detection recoveryError detection recovery
Error detection recovery
Tech_MX
 
(D 15 180770107240)
(D 15 180770107240)(D 15 180770107240)
(D 15 180770107240)
RaviModi37
 
A Survey Of Systems For Detecting Serial Run-Time Errors
A Survey Of Systems For Detecting Serial Run-Time ErrorsA Survey Of Systems For Detecting Serial Run-Time Errors
A Survey Of Systems For Detecting Serial Run-Time Errors
Lisa Graves
 
Compiler design error handling
Compiler design error handlingCompiler design error handling
Compiler design error handling
RohitK71
 
Computer programing 111 lecture 2
Computer programing 111 lecture 2Computer programing 111 lecture 2
Computer programing 111 lecture 2
ITNet
 
Ad

Recently uploaded (20)

Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Ad

Error Handling in Compiler Design.doctyp

  • 1. Error Handling in Compiler Design The tasks of the Error Handling process are to detect each error, report it to the user, and then make some recovery strategy and implement them to handle the error. During this whole process processing time of the program should not be slow. Functions of Error Handler:  Error Detection  Error Report  Error Recovery Error handler=Error Detection+Error Report+Error Recovery. An Error is the blank entries in the symbol table. Errors in the program should be detected and reported by the parser. Whenever an error occurs, the parser can handle it and continue to parse the rest of the input. Although the parser is mostly responsible for checking for errors, errors may occur at various stages of the compilation process. So, there are many types of errors and some of these are: Types or Sources of Error – There are three types of error: logic, run-time and compile-time error: Logic errors occur when programs operate incorrectly but do not terminate abnormally (or crash). Unexpected or undesired outputs or other behaviour may result from a logic error, even if it is not immediately recognized as such. 1. A run-time error is an error that takes place during the execution of a program and usually happens because of adverse system parameters or invalid input data. The lack of sufficient memory to run an application or a memory conflict with another program and logical error is an example of this. Logic errors occur when executed code does not produce the expected result. Logic errors are best handled by meticulous program debugging. 2. Compile-time errors rise at compile-time, before the execution of the program. Syntax error or missing file reference that prevents the program from successfully compiling is an example of this.
  • 2. Classification of Compile-time error – 1. Lexical : This includes misspellings of identifiers, keywords or operators 2. Syntactical : a missing semicolon or unbalanced parenthesis 3. Semantical : incompatible value assignment or type mismatches between operator and operand 4. Logical : code not reachable, infinite loop. Finding error or reporting an error – Viable-prefix is the property of a parser that allows early detection of syntax errors.  Goal detection of an error as soon as possible without further consuming unnecessary input  How: detect an error as soon as the prefix of the input does not match a prefix of any string in the language.
  • 3. Example: for(;), this will report an error as for having two semicolons inside braces. Error Recovery – The basic requirement for the compiler is to simply stop and issue a message, and cease compilation. There are some common recovery methods that are as follows. We already discuss the errors. Now, let’s try to understand the recovery of errors in every phase of the compiler. 1. Panic mode recovery : This is the easiest way of error-recovery and also, it prevents the parser from developing infinite loops while recovering error. The parser discards the input symbol one at a time until one of the designated (like end, semicolon) set of synchronizing tokens (are typically the statement or expression terminators) is found. This is adequate when the presence of multiple errors in the same statement is rare. Example: Consider the erroneous expression- (1 + + 2) + 3. Panic-mode recovery: Skip ahead to the next integer and then continue. Bison: use the special terminal error to describe how much input to skip. E->int|E+E|(E)|error int|(error) 2. Phase level recovery : When an error is discovered, the parser performs local correction on the remaining input. If a parser encounters an error, it makes the necessary corrections on the remaining input so that the parser can continue to parse the rest of the statement. You can correct the error by deleting extra semicolons, replacing commas with semicolons, or reintroducing missing semicolons. To prevent going in an infinite loop during the
  • 4. correction, utmost care should be taken. Whenever any prefix is found in the remaining input, it is replaced with some string. In this way, the parser can continue to operate on its execution. 3. Error productions : The use of the error production method can be incorporated if the user is aware of common mistakes that are encountered in grammar in conjunction with errors that produce erroneous constructs. When this is used, error messages can be generated during the parsing process, and the parsing can continue. Example: write 5x instead of 5*x 4. Global correction : In order to recover from erroneous input, the parser analyzes the whole program and tries to find the closest match for it, which is error-free. The closest match is one that does not do many insertions, deletions, and changes of tokens. This method is not practical due to its high time and space complexity. Advantages of Error Handling in Compiler Design: 1.Robustness: Mistake dealing with improves the strength of the compiler by permitting it to deal with and recuperate from different sorts of blunders smoothly. This guarantees that even within the sight of blunders, the compiler can keep handling the information program and give significant mistake messages. 2.Error location: By consolidating blunder taking care of components, a compiler can distinguish and recognize mistakes in the source code. This incorporates syntactic mistakes, semantic blunders, type blunders, and other potential issues that might make the program act startlingly or produce erroneous result. 3.Error revealing: Compiler mistake taking care of works with viable blunder answering to the client or software engineer. It creates engaging blunder messages that assist developers with understanding the nature and area of the mistake, empowering them to effectively fix the issues. Clear and exact mistake messages save designers significant time in the troubleshooting system. 4.Error recuperation: Mistake dealing with permits the compiler to recuperate from blunders and proceed with the aggregation cycle whenever the situation allows. This is accomplished through different methods like blunder adjustment, mistake synchronization, and resynchronization. The compiler endeavors to redress the blunders and continues with assemblage, keeping the whole interaction from being ended unexpectedly. 5.Incremental gathering: Mistake taking care of empowers gradual aggregation, where a compiler can order and execute right partitions of the program regardless of whether different segments contain blunders. This element is especially helpful for enormous scope projects, as it permits engineers to test and investigate explicit modules without recompiling the whole codebase.
  • 5. 6.Productivity improvement: With legitimate mistake taking care of, the compiler diminishes the time and exertion spent on troubleshooting and blunder fixing. By giving exact mistake messages and supporting blunder recuperation, it assists programmers with rapidly recognizing and resolve issues, prompting further developed efficiency and quicker advancement cycles. 7.Language turn of events: Mistake taking care of is a fundamental part of language plan and advancement. By consolidating mistake dealing with systems in the compiler, language fashioners can characterize the normal blunder conduct and authorize explicit standards and imperatives. This adds to the general dependability and consistency of the language, guaranteeing that developers stick to the expected utilization designs. Disadvantages of error handling in compiler design: Increased complexity: Error handling in compiler design can significantly increase the complexity of the compiler. This can make the compiler more challenging to develop, test, and maintain. The more complex the error handling mechanism is, the more difficult it becomes to ensure that it is working correctly and to find and fix errors. Reduced performance: Error handling in compiler design can also impact the performance of the compiler. This is especially true if the error handling mechanism is time-consuming and computationally intensive. As a result, the compiler may take longer to compile programs and may require more resources to operate. Increased development time: Developing an effective error handling mechanism can be a time-consuming process. This is because it requires significant testing and debugging to ensure that it works as intended. This can slow down the development process and result in longer development times. Difficulty in error detection: While error handling is designed to identify and handle errors in the source code, it can also make it more difficult to detect errors. This is because the error handling mechanism may mask some errors, making it harder to identify them. Additionally, if the error handling mechanism is not working correctly, it may fail to detect errors altogether. Next related article – Error detection and Recovery in Compiler Here's a complete roadmap for you to become a developer: Learn DSA -> Master Frontend/Backend/Full Stack -> Build Projects -> Keep Applying to Jobs And why go anywhere else when our DSA to Development: Coding Guide helps you do this in a single program! Apply now to our DSA to Development Program and our counsellors will connect with you for further guidance & support.
  • 6. Difference between Recursive Predictive Descent Parser and Non- Recursive Predictive Descent Parser    Prerequisite – Recursive Descent Parser 1. Recursive Predictive Descent Parser : Recursive Descent Parser is a top-down method of syntax analysis in which a set of recursive procedures is used to process input. One procedure is associated with each non-terminal of a grammar. Here we consider a simple form of recursive descent parsing called Predictive Recursive Descent Parser, in which look-ahead symbol unambiguously determines flow of control through procedure body for each non- terminal. The sequence of procedure calls during analysis of an input string implicitly defines a parse tree for input and can be used to build an explicit parse tree, if desired. In recursive descent parsing, parser may have more than one production to choose from for a single instance of input there concept of backtracking comes into play. Back-tracking – It means, if one derivation of a production fails, syntax analyzer restarts process using different rules of same production. This technique may process input string more than once to determine right production.Top- down parser start from root node (start symbol) and match input string against production rules to replace them (if matched). To understand this, take following example of CFG : S -> aAb | aBb A -> cx | dx B -> xe
  • 7. For an input string – read, a top-down parser, will behave like this. It will start with S from production rules and will match its yield to left-most letter of input, i.e. ‘a’. The very production of S (S -> aAb) matches with it. So top-down parser advances to next input letter (i.e., ‘d’). The parser tries to expand non-terminal ‘A’ and checks its production from left (A -> cx). It does not match with next input symbol. So top-down parser backtracks to obtain next production rule of A, (A -> dx). Now parser matches all input letters in an ordered manner. The string is accepted. 2. Non-Recursive Predictive Descent Parser : A form of recursive-descent parsing that does not require any back-tracking is known as predictive parsing. It is also called as LL(1) parsing table technique since we would be building a table for string to be parsed. It has capability to predict which production is to be used to replace input string. To accomplish its tasks, predictive parser uses a look-ahead pointer, which points to next input symbols. To make parser back-tracking free, predictive parser puts some constraints on grammar and accepts only a class of grammar known as LL(k) grammar.
  • 8. Predictive parsing uses a stack and a parsing table to parse input and generate a parse tree. Both stack and input contains an end symbol $ to denote that stack is empty and input is consumed. The parser refers to parsing table to take any decision on input and stack element combination. There might be instances where there is no production matching input string, making parsing procedure to fail. Difference between Recursive Predictive Descent Parser and Non-Recursive Predictive Descent Parser : Recursive Predictive Descent Parser Non-Recursive Predictive Descent Parser It is a technique which may or may not require backtracking process. It is a technique that does not require any kind of backtracking. It uses procedures for every non-terminal entity to parse strings. It finds out productions to use by replacing input string. It is a type of top-down parsing built from a set of mutually recursive procedures where each procedure implements one of non- terminal s of grammar. It is a type of top-down approach, which is also a type of recursive parsing that does not uses technique of backtracking. It contains several small The predictive parser uses a look
  • 9. Recursive Predictive Descent Parser Non-Recursive Predictive Descent Parser functions one for each non- terminals in grammar. ahead pointer which points to next input symbols to make it parser back tracking free, predictive parser puts some constraints on grammar. It accepts all kinds of grammars. It accepts only a class of grammar known as LL(k) grammar.