Error Detection Recovery
Error Detection Recovery
AND RECOVERY
12/11/2024 1
ERROR
of various kinds So, good compiler should be able
• Program submitted to a compiler often have errors
• * ALGORITHMIC ERRORS:
The algorithm used to meet the design may be inadequate
or incorrect
*CODING ERRORS:
The programmer may introduce errors in implementing the
algorithms, either by introducing logical errors or using the
programming language constructs improperly
• *The program may exceed a compiler or machine limit
not implied by the definition of the programming
language.
• Eg:
• An array may be declared with too many dimensions to
fit in the symbol table ,
• an array may be declared with too large to be allocated
at runtime.
• *COMPILER ERRORS:
• compiler can insert errors as it translates source
program into an object program.
ERROR CLASSIFICATION
• CRETERIA FOR THE CLASSIFICATION OF ERRORS:
• *Compile time,
• *Link / Load time
• * Run time errors.
• The lexical and syntactic errors are found during the
execution of the program.
• Most of the run time errors are semantic in nature.
• In compile-link-go systems, the compile and link errors
will be trapped seperately by the compiler and the
linkage editor / loader.
• In compile-and-go systems, the compile and link errors
will be trapped by the compiler itself.
• Execution time errors are detected by the run time
environment, which includes runtime control routine,
the machine hardware and the standard OS interfaces
through which status of the hardware can be accessed
or monitored as when required.
PLAN OF ERROR DETECTOR /
CORRECTOR
Diagnosti
c
Message
Printer
Symbol
Table
Lexical Syntactic
corrector corrector
Source Intermedia
code Lexical Tokens Semantic
Parser te
analyzer checker
code
12/11/2024 10
LEXICAL AND SYNTAX ERRORS
1.Spelling errors,
2.Missing operators and keywords
12/11/2024 12
Syntactic phase Error
• Missing parenthesis
• e.g. prinf(“Hello”;
• Missing Operator
e.g. x+yz
• Misspelled Keyword
• E.g. swicth(ch)
{
}
• Colon in place of semicolon (a=1;)
• Extra blank space /* comment * /
12/11/2024 13
12/11/2024 14
SPELLING ERRORS- WHEN DO
THEY OCCUR???
If a program uses variables names which differs in
only one or two characters ,then there exits great
scope for spelling errors.
12/11/2024 19
Panic mode recovery
on discovering an error
the parser discards input symbols one at a time
until is found one of a designated set of synchronizing
tokens
◦ delimiters ; or }
◦ have a clear and unambiguous role
◦ must be selected by the compiler designer
skips considerable amount of input
no checking for additional errors
simple
guaranteed not to go on an infinite loop
12/11/2024 20
• Three basic policy of recovering syntax error:
• 1.Deletion of a source symbol
• 2.Insertion of a synthetic symbol.
• 3.Replacement.
12/11/2024 21
• The motive behind all these actions is to present a new
string to the parser which would lead to bypassing the
error situation and continue to parse.
• Here multiple recovery possibilities may exists.
• We should choose the one which has smallest number
of changes – minimum distance recovery
12/11/2024 22
RECOVERY IN TOP DOWN
PARSING
• There are two methods.
• First is to try and successfully complete the predictions
existing in the stack at the error point.
Ex: Input string: Aα
• Last prediction was W:…ABν
• If no other rules exit with A on right hand side then
recovery can be effected by inserting B and deleting
parts a until a ν is recognized in source string.
• Another is unstack certain symbols from parser stack
until we have a TOS symbol which can produce one of
the synchronizing symbols.
• We can skip until we find a synchronising symbol in
input stack
OPERATOR PRECEDENCE
PARSING
Operator precedence parser uses set of
production rules and operator precedence table
to parse an arithmetic expression.
E→E+E
|E–E
|E*E
|E/E
|E^E
|(E)
|-E
| id
CHARACTER PAIR ERROR
RECOVERY
Example,
3 Fatal error. Compilation continues but the compiled program will not execute
Message text
Runtime errors
• Arithmetic exceptions
Arises because of the violations of semantics of
machine computations.
Includes frequently occurring error conditions like
overflows, underflows, loss of precision etc..
Present day architecture detects most of the
conditions at the machine hardware level and
indicate their presence through interrupts or
traps
12/11/2024 36
QUERIES??
Slide:37