0% found this document useful (0 votes)
10 views12 pages

Error Handling

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views12 pages

Error Handling

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Error Handling

COMPILER
DESIGN
Name: Kashish Ali Khan
Roll No.: 2100290100086
CONTENTS
• Phases of a Compiler
• Error Handling
• What is an error?
• Types of Error
• Classification of Compile-time error –
• Finding error or reporting an error
• Error Recovery
• Advantages of Error Handling
• Disadvantages of error handling
PHASES OF A
COMPILER
The tasks of the Error Handling process are to detect
each error, report it to the user, and then make some

Error recovery strategy and implement them to handle the


error. During this whole process processing time of the

Handling program should not be slow.

Functions of Error Handler:


• Error Detection
• Error Report
• Error Recovery
WHAT IS AN ERROR?

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:
• logic error
• run-time error
• compile-time error
TYPES OF
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.
• 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.
• 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 • Lexical : This includes misspellings of identifiers,
OF COMPILE-TIME keywords or operators
• Syntactical : a missing semicolon or unbalanced
ERROR – parenthesis
• Semantical : incompatible value assignment or
type mismatches between operator and operand
• Logical : code not reachable, infinite loop.
FINDING ERROR
Viable-prefix is the property of a parser that allows
OR REPORTING early detection of syntax errors.

AN ERROR • 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.
ERROR
R E C O V E RY
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.
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 is found.
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.
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.
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.
A D VA N TA G E S O F E R R O R H A N D L I N G
• Robustness: Error handling strengthens compiler resilience by managing various errors, ensuring ongoing
program processing even amidst errors.
• Error Detection: Enables identification of syntax, semantic, and type errors, guaranteeing accurate code behavior.
• Error Reporting: Generates clear, informative messages aiding swift issue resolution, saving debugging time.
• Error Recovery: Allows the compiler to continue compiling by correcting errors, preventing abrupt halts.
• Incremental Compilation: Permits compilation of correct sections, aiding focused debugging in large projects.
• Productivity: Reduces debugging time, fostering quicker issue resolution and enhanced development pace.
• Language Consistency: Supports language designers in defining expected error behavior, maintaining usage
patterns, ensuring stability.
D I S A D VA N TA G E S O F E R R O R
HANDLING

• Complexity: Implementing error handling increases the intricacy of compiler development, testing,
and maintenance, posing challenges in ensuring its correctness and debugging.
• Performance Impact: Error handling mechanisms, especially time-consuming ones, can reduce
compiler performance, leading to longer compilation times and increased resource consumption.
• Extended Development Time: Creating an effective error handling system demands extensive
testing and debugging, elongating the development process.
• Error Detection Difficulty: While designed to catch errors, error handling might obscure certain
issues, complicating error identification. If the mechanism fails, it could even miss errors entirely,
further complicating the detection process.
THANK YOU

You might also like