0% found this document useful (0 votes)
34 views

Error Detection Recovery

Uploaded by

kmngl47
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)
34 views

Error Detection Recovery

Uploaded by

kmngl47
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/ 37

ERROR ANALYSIS , DETECTION

AND RECOVERY

12/11/2024 1
ERROR
of various kinds So, good compiler should be able
• Program submitted to a compiler often have errors

to detect as many errors as possible in


various ways and also recover from them
12/11/2024 3
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
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

• 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.
Lexical Phase Error

• Exceeding length of Identifier


E.g. int sum; (more than 31 charaacters in c)
• Appearance of illegal character (e.g. int a , $)
• Unmatched string or comment
• (ex. “hello or /* )

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.

 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. One character is wrong,


2. One character is missing,
3. One character is extra,
4. 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 it’s correct configuration , which
is determined by it’s 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 it’s input from left to right can announce
an error
• Adv – reports errors as soon as possible
• Limits amount of erroneous output

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

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
• Can’t 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 it’s error severity
• This value is mainly used for purposes internal to the
compiler’s operation
1 Warning and correction. Compilation continues and the compiled program will
execute
2 Warning only. Compilation continues and compiled program will execute

3 Fatal error. Compilation continues but the compiled program will not execute

4 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 statement Auxiliary information


number(Message
identifier)

Message text
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/11/2024 36
QUERIES??

Slide:37

You might also like