CD Unit3
CD Unit3
VI SEMESTER
ETCS-302
Symbol Table
Error Handling
Error Recovery
/*..............* /
The keyword switch is incorrectly written as swicth.
Hence, “Unidentified keyword/identifier” error
occurs.
Department of Computer Science and Engineering, BVCOE, New Delhi
18
Error recovery:
Panic Mode Recovery
In this method, successive characters from input are
removed one at a time until a designated set of
synchronizing tokens is found. Synchronizing tokens are
deli-meters such as ; or }
Advantage is that its easy to implement and guarantees
not to go to infinite loop
Disadvantage is that a considerable amount of input is
skipped without checking it for additional errors
Global Correction
The parser examines the whole program and tries to find out the closest match
for it which is error free.
The closest match program has less number of insertions, deletions and
changes of tokens to recover from erroneous input.
Due to high time and space complexity, this method is not implemented
practically.
Department of Computer Science and Engineering, BVCOE, New Delhi
22
Semantic errors
These errors are detected during semantic analysis phase.
Typical semantic errors are
Incompatible type of operands a*b
Undeclared variables
Not matching of actual arguments with formal one
Example : int a[10], b;
.......
.......
a = b;
It generates a semantic error because of an incompatible type
of a and b.
Department of Computer Science and Engineering, BVCOE, New Delhi
23
Error recovery
If error “Undeclared Identifier” is encountered then,
to recover from this a symbol table entry for
corresponding identifier is made.
If data types of two operands are incompatible then,
automatic type conversion is done by the compiler.