2
Most read
7
Most read
8
Most read
ERROR HANDLING
&
ERROR RECOVERY
COMPILER DESIGN
INTRODUCTION
The tasks of the Error Handling process are to detect each error, report it to the user, and then make
some recover strategy and implement them to handle error.
During this whole process processing time of program should not be slow. An Error is the blank
entries in the symbol table.
TYPES OF ERROR
Types or Sources of Error :
1. Run-time error - It is an error which takes place during the execution of a program,
and usually happens because of adverse system parameters or invalid input data.
2. Compile-time error - It rises at compile time, before execution of the program.
Classification of Compile-time error
● Lexical : name of some identifier typed incorrectly
● Syntactical : missing semicolon or unbalanced parenthesis
● Semantical : incompatible value assignment
● Logical : code not reachable, infinite loop
Finding error or reporting an error
Goal How Example
for(;)
ERROR RECOVERY
1. Panic mode
2. Statement mode
3. Error productions
4. Global correction
PANIC MODE
● This is the easiest way of error-recovery.
● It prevents the parser from developing infinite loops while recovering error.
● When a parser encounters an error anywhere in the statement, it ignores the rest of
the statement by not processing input from erroneous input to delimiter, such as
semicolon.
● Example:
E->int|E+E|(E)|error int|(error)
STATEMENT MODE
● When a parser encounters an error, it tries to take corrective measures so that the rest
of inputs of statement allow the parser to parse ahead.
● Parser designers have to be careful here because one wrong correction may lead to an
infinite loop.
● For example, inserting a missing semicolon.
ERROR PRODUCTIONS
● Some common errors are known to the compiler designers that may occur in the
code.
● Augmented grammars can also be used, as productions that generate erroneous
constructs when these errors are encountered.
● Example: write 5x instead of 5*x
GLOBAL CORRECTION
● The parser considers the program in hand as a whole and tries to figure out what the
program is intended to do and tries to find out a closest match for it, which is error-free.
● Its aim is to make as few changes as possible while converting an incorrect input string to
a valid string.
● This strategy is costly to implement.
ERROR RECOVERY
ERROR RECOVERY FOR SEMANTIC TYPE OF ERRORS
“Undeclared Identifier”
● If error “Undeclared Identifier” is encountered then, to recover from this a
symbol table entry for corresponding identifier is made.
● If data types of two operands are incompatible then, automatic type
conversion is done by the compiler.
“
”
CONCLUSION
A parser should be able to detect and report any error in the program. It is expected that when an error
is encountered, the parser should be able to handle it and carry on parsing the rest of the input.
So, we saw how many types of errors may occur and also how to recover those errors with clear
examples.
THANK YOU

Compiler design error handling

  • 1.
  • 2.
    INTRODUCTION The tasks ofthe Error Handling process are to detect each error, report it to the user, and then make some recover strategy and implement them to handle error. During this whole process processing time of program should not be slow. An Error is the blank entries in the symbol table.
  • 3.
    TYPES OF ERROR Typesor Sources of Error : 1. Run-time error - It is an error which takes place during the execution of a program, and usually happens because of adverse system parameters or invalid input data. 2. Compile-time error - It rises at compile time, before execution of the program.
  • 4.
    Classification of Compile-timeerror ● Lexical : name of some identifier typed incorrectly ● Syntactical : missing semicolon or unbalanced parenthesis ● Semantical : incompatible value assignment ● Logical : code not reachable, infinite loop
  • 5.
    Finding error orreporting an error Goal How Example for(;)
  • 6.
    ERROR RECOVERY 1. Panicmode 2. Statement mode 3. Error productions 4. Global correction
  • 7.
    PANIC MODE ● Thisis the easiest way of error-recovery. ● It prevents the parser from developing infinite loops while recovering error. ● When a parser encounters an error anywhere in the statement, it ignores the rest of the statement by not processing input from erroneous input to delimiter, such as semicolon. ● Example: E->int|E+E|(E)|error int|(error)
  • 8.
    STATEMENT MODE ● Whena parser encounters an error, it tries to take corrective measures so that the rest of inputs of statement allow the parser to parse ahead. ● Parser designers have to be careful here because one wrong correction may lead to an infinite loop. ● For example, inserting a missing semicolon.
  • 9.
    ERROR PRODUCTIONS ● Somecommon errors are known to the compiler designers that may occur in the code. ● Augmented grammars can also be used, as productions that generate erroneous constructs when these errors are encountered. ● Example: write 5x instead of 5*x
  • 10.
    GLOBAL CORRECTION ● Theparser considers the program in hand as a whole and tries to figure out what the program is intended to do and tries to find out a closest match for it, which is error-free. ● Its aim is to make as few changes as possible while converting an incorrect input string to a valid string. ● This strategy is costly to implement.
  • 11.
    ERROR RECOVERY ERROR RECOVERYFOR SEMANTIC TYPE OF ERRORS “Undeclared Identifier” ● If error “Undeclared Identifier” is encountered then, to recover from this a symbol table entry for corresponding identifier is made. ● If data types of two operands are incompatible then, automatic type conversion is done by the compiler.
  • 12.
    “ ” CONCLUSION A parser shouldbe able to detect and report any error in the program. It is expected that when an error is encountered, the parser should be able to handle it and carry on parsing the rest of the input. So, we saw how many types of errors may occur and also how to recover those errors with clear examples.
  • 13.