Top Banner
ERROR DETECTION AND RECOVERY 06/24/2022 1
35

Error Detection _ Recovery

Feb 18, 2016

Download

Documents

jayakrrishnan

Error Detection _ Recovery
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Error Detection _ Recovery

04/22/2023 1

ERROR DETECTION AND RECOVERY

Page 2: Error Detection _ Recovery

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

Page 3: Error Detection _ Recovery

04/22/2023 3

Page 4: Error Detection _ Recovery

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

Page 5: Error Detection _ Recovery

• *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.

Page 6: Error Detection _ Recovery

ERROR CLASSIFICATION

Page 7: Error Detection _ Recovery

• CRETERIA FOR THE CLASSIFICATION OF ERRORS:• *Compile time,• *Link / Load time • * Run time errors.

Page 8: Error Detection _ Recovery

• 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. 

Page 9: Error Detection _ Recovery

• 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.

Page 10: Error Detection _ Recovery

PLAN OF ERROR DETECTOR / CORRECTOR

04/22/2023 10

Lexical analyzer

Lexical corrector

Diagnostic Message PrinterSyntactic corrector

Parser

Symbol Table

Semantic checkerSource code Tokens Intermediate

code

Page 11: Error Detection _ Recovery

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.

Page 12: Error Detection _ Recovery

04/22/2023 12

Page 13: Error Detection _ Recovery

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.

Page 14: Error Detection _ Recovery

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

Page 15: Error Detection _ Recovery

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.

Page 16: Error Detection _ Recovery

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

Page 17: Error Detection _ Recovery

04/22/2023 17

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 erraneous output

Page 18: Error Detection _ Recovery

04/22/2023 18

Panic mode recoveryon discovering an errorthe parser discards input symbols one at a timeuntil 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 inputno checking for additional errorssimpleguaranteed not to go on an infinite loop

Page 19: Error Detection _ Recovery

04/22/2023 19

• Three basic policy of recovering syntax error:• 1.Deletion of a source symbol• 2.Insertion of a synthetic symbol.• 3.Replacement.

Page 20: Error Detection _ Recovery

04/22/2023 20

• 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

Page 21: Error Detection _ Recovery

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

Page 22: Error Detection _ Recovery

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

Page 23: Error Detection _ Recovery

CHARACTER PAIR ERROR RECOVERY

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

E1 – ‘missing operand’ – whole expression is missingE2- ‘unbalanced right parenthesis’E3- ‘missing operator’E4- ‘missing right parenthesis’

Page 24: Error Detection _ Recovery

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

Page 25: Error Detection _ Recovery

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.

Page 26: Error Detection _ Recovery

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

Page 27: Error Detection _ Recovery

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

Page 28: Error Detection _ Recovery

1 Warning and correction. Compilation continues and the compiled program will execute2 Warning only. Compilation continues and compiled program will execute3 Fatal error. Compilation continues but the compiled program will not execute4 Compiler error . Compilation terminated

Page 29: Error Detection _ Recovery

• 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.

Page 30: Error Detection _ Recovery

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

Page 31: Error Detection _ Recovery

• The compiler error table will be in the form Error number(Message identifier) Erroneous statement Auxiliary information

Message text

Page 32: Error Detection _ Recovery

Runtime errors

• The runtime errors are detected by1. The run time control routine which is interfaced with the generated code in standard manner2. The machine hardware3 . Operating system interfaces to I/O

Page 33: Error Detection _ Recovery

• 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

Page 34: Error Detection _ Recovery

04/22/2023 34

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

Page 35: Error Detection _ Recovery

Slide:35

QUERIES??