You are on page 1of 35

ERROR DETECTION AND

RECOVERY

12/2/15

ERROR
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 and also recover from them

12/2/15

SOURCES OF ERROR

* 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

Lexical
corrector

Source
code

12/2/15

Lexical
analyzer

Symbol
Table

Syntactic
corrector

Tokens

Parser

Intermediate
code

10

Semantic
checker

LEXICAL AND SYNTAX ERRORS


Two frequent sources of these errors are:
1.Spelling errors,
2.Missing operators and keywords
These errors can happen due to genuine
oversight or due to typing mistake.
They are common mistakes for even for
professional programmers.

12/2/15

12

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.
There is less chance for using automatic
procedures for detecting and correcting these
errors.
Only the programmer can able to tackle the
problem because he only know about significance
of variable names.

MAJORITY SPELLING ERRORS


1.
2.
3.
4.

One character is wrong,


One character is missing,
One character is extra,
Two adjacent characters are transposed.

Testing for these four types of error will not enable us to


catch all the spelling mistakes but practical consideration
limit searches to these four only
The implementation these four checks is quite expensive
because an associative search has to be performed over
all names in symbol table to locate resembling name

DUPLICATE MASSAGE
It is to find that many message appear owing to
the same error.
Ex: If a is used as a simple variable and later
goes to declare and use it as array a[10,10] then
all references to the array will be flagged as
erroneous use of variable name.
This can achieved by setting a flag in the symbol
table entry of a.
This will enable to detect and indicate all possible
illegal use of identifier.

RECOVERING FROM SYNTAX


ERROR
The chief concern while recovering from the
syntax error is to attain a parser state from where
the parser can safely resume parsing the input
string.
Many parsers detects errors when it doesnot have
legal move from its correct configuration , which
is determined by its state , stack content and
current input symbol.
To recover from an error a parser should ideally
locate it , correct and resume parsing

TIME OF DETECTION VALID


PREFIX PROPERTY
LL1 AND LR1 parsers will announce errors as soon
as the prefix of the input has been seen for which
there is no valid continuation
This is the earliest time at which a parser that
reads its input from left to right can announce an
error
Adv reports errors as soon as possible
Limits amount of erraneous output

12/2/15

17

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/2/15

18

Three basic policy of recovering syntax error:


1.Deletion of a source symbol
2.Insertion of a synthetic symbol.
3.Replacement.

12/2/15

19

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
12/2/15
minimum distance recovery 20

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.
EE+E
|EE
|E*E
|E/E
|E^E
|(E)
|-E
| id

CHARACTER PAIR ERROR


RECOVERY
Fill each empty entry with a pointer to an error
routine.
Example,

E1 missing operand whole expression is


missing
E2- unbalanced right parenthesis
E3- missing operator
E4- missing right parenthesis

REDUCIBILITY ERROR RECOVERY


Decides the popped handle looks like which
right hand side. And tries to recover from that
situation.
Same like shift-reduce errors

SEMANTIC ERRORS
Can be detected both at compile time and run tume
Can be both local and global in scope.
Types
Immediate errors
Can be detected while processing the
erroneous statement itself.
Delayed errors
Cant be detected while processing the
statement.
But can be detected at a later stage when its
effect is felt.

EXAMPLES FOR SEMANTIC ERRORS


Illegal Operator or Operand (immediate)
Control Structure Violation (both)
Missing Labels
(delayed at the end of
the
program)
Duplicate Labels
Most common semantic errors that can be
detected at compile time are errors of declaration
and scope
Eg type incompatability between operators and
operands

THE ERROR PRINT ROUTINE


Messages have to be displayed for all errors which
are detected , or detected and corrected in the
source program.
The error print routine is the common agency that is
used by all individual compiler routines for this
purpose.
The text of the error is normally stored in the table
local to this routine
Associated with each message is the numerical value
indicating its error severity
This value is mainly used for purposes internal to the
compilers operation

Warning and correction. Compilation continues and the


compiled program will execute

Warning only. Compilation continues and compiled program will


execute

Fatal error. Compilation continues but the compiled program


will not execute

Compiler error . Compilation terminated

For each individual error two items of


information need to be passed to this
routine
The error number and the statement
number
The structure and logic of the routine
depends largely on the decisions
regarding the place where the
message is to be printed.

Desirable place for printing error


messages
The messages are best printed against
the erraneous statement itself
Single pass compilers find it difficult to
indicate all errors against the offending
statement
Multipass compilers can provide such
error condition

The compiler error table will be in the


form
Error
Erroneous
number(Mess statement
age identifier)

Message text

Auxiliary
information

Runtime errors
The runtime errors are detected by
1. The run time control routine which is
interfaced with the generated code
in standard manner
2. The machine hardware
3 . Operating system interfaces to I/O

The agency required to detect


particular type of error depends on
nature of error and in general varies
from machine to machine and
compiler to compiler

Detection of 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/2/15

34

QUERIES??

Slide:35

You might also like