Error Detection Recovery
Error Detection Recovery
8/31/2012
CONTENTS
8/31/2012
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 (i.e) even in the presence of errors ,the compiler should scan the program and try to compile all of it.(error recovery).
when the scanner or parser finds an error and cannot proceed , the compiler must modify the input so that the correct portions of the program can be pieced together and successfully proessed in the syntax analysis phase. Therefore , there should be a considerable forethought from the beginning in designing the compiler.
various ways: After the detection of a error, * a simple compiler may stop all the activities other than lexical and syntactic analysis. * a more complex compiler may transform the erroneous input into a similar legal input on which the normal processing can be resumed(repair).
*an even more sophisticated compiler may correct the erroneous input by guessing what the user has intended. However, no compiler can do true correction.Because,compiler wont know the intent of the programmer due to errors. Completely accurate error correction can be done only by the programmer.
DIAGNOSTIC COMPILER
Compilers giving due importance to all the 3 aspects is called Diagnostic compilers, which follows complex analysis task, which may require extra time or memory space. Eg: WATFOR, IITFORT
CORRECTING COMPILER
These compilers does the job of error recovery not only from the compiler point of view but also from the programmers point of view(ie) generates code to be executed, which eases the programmer. Eg:PL/C But at the same time, error recovery should not lead to misleading or spurious error messages elsewhere (error propagation).
Indication of run time errors is another neglected area in compiler design. Because, code generated to monitor these violations increases the target program size, which leads to slow execution. So these checks are included as debugging options(also includes intermediate display of values, trace of procedure calls) at the cost of additional amount.
Good error reporting plays an important role in the construction of reliable programs. PROPERTIES OF GOOD ERROR DIAGNOSIS: *The messages should pinpoint the errors in terms of original source program rather than in some internal representation, which is unknown to the user. *The error messages should be tasteful and understandable by the user. Eg: Showing error as missing right parenthesis in line 5 rather than as a cryptic code OH17 *The messages should be specific and should localize the problem Eg: Showing error as Z not declared in procedure add rather than missing declaration. *The massages should not be redundant. Eg: If z is not declared, then it should be said once not every time z appears in the program.
Eg: Showing error as missing right parenthesis in line 5 rather than as a cryptic code OH17 *The messages should be specific and should localize the problem Eg: Showing error as Z not declared in procedure add rather than missing declaration. *The massages should not be redundant. Eg: If z is not declared, then it should be said once not every time z appears in the program.
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.
CRETERIA FOR THE CLASSIFICATION OF ERRORS: *Compile time, *Link / Load time * Run time errors.
CLASSIFICATION OF COMPILE TIME ERRORS: *lexical errors * Syntactic errors * Semantic 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.
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.
8/31/2012
19
After detecting and reporting error , a phase can either repair it or pass it along to the subsequent modules. If a phase attempts repair , it should take precautions that the repair does not introduce a flurry of other errors If a phase transmits error the subsequent phase should be able to deal with the erroneous inputs passed on.
8/31/2012
21
Source code
Lexical analyzer
Tokens
Parser
Intermediate code
Semantic checker
22
8/31/2012
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
CORRECTION ALGORITHM
The searching try to mask off one or more adjacent characters from symbols and locate a matching symbol from symbol table. The located symbol can be used instead of erroneous symbol if only one character was masked off If two characters were masked then transposition should be checked . If associative search for an erroneous names matches more than one symbol in the symbol table then In that case their attributes are used to decide the final. If more than one symbol with matching attributes result then correction is not safe and should not be attempted. This algorithm may fail if unusual usage of names results from valid usage of language facilities. So it is necessary to inform the user whenever one correction made.
Otherwise the couldnt produce any error since H could later be declared to be a function or an array.
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.
8/31/2012
30
8/31/2012
31
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
8/31/2012
32
Three basic policy of recovering syntax error: 1.Deletion of a source symbol 2.Insertion of a synthetic symbol. 3.Replacement.
8/31/2012
33
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
8/31/2012 34
E1 missing operand whole expression is missing E2- unbalanced right parenthesis E3- missing operator E4- missing right parenthesis
But what if there is a choice? If it is legal to shift or reduce, there is a shift-reduce conflict If it is legal to reduce by two different productions, there is a reduce-reduce conflict
SEMANTIC ERRORS
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.
1 2 3 4
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.
Many Fortran compilers indicate errors on a line by line basis as far as possible since syntax analysis and output listing are both performed in the same normally first pass Some compilers group all error messages at end of the program. This has the advantages that the problem of duplicate messages for similar misuse of an identifier can be satisfactorily solved.
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
8/31/2012
53
Input output errors Device error conditions and end of file conditions on input file are usually detected by IOCS which sets appropriate flag to indicate their occurance The runtime control routine should make appropraite provisions to obtain control when such conditions arise Ex: fortran programmer stmt read(5,100,err=110,end=120) A,B Appropriate code take control to line 120 on eof and 110 on error
8/31/2012 54
Dimensions overruns overall array bound check Individual subscript bound check Watfor compilers do these
8/31/2012
55
Subscript Range
I=5
Compiler generates code for inserting and deleting entries from the program action fields depending on the scope of the program-indicated recovery actions. Type of Exception Scope Recovery action stack pointer Overflow -------------------Subscript range ------------------- Scope column indicate where the scope of the programmer indicated recovery action ends.
Assignment Checks
Assignments to a variable are monitored by the system. If the new value is assigned to a variable, which will be the output.
Conversational debugging
Facilities are provided through which the programmer can set the break points in the program. When the program reach the break point, a conversation is initiated with the programmer. Ex, Assigining values and Displaying the values.
QUERIES??
Slide:61