Error Handler: Presented By: Junaid Khan Department of Computer Science University of Peshawar
Error Handler: Presented By: Junaid Khan Department of Computer Science University of Peshawar
Presented by:
Junaid Khan
Department of Computer Science
University of Peshawar
Compiler Errors
Errors
An Error is an abnormal condition in the
source program which either stops the
compilation or results in undesired output.
Programs submitted to a compiler often
have errors of various kinds.
With regard to errors, most compilers are
not very effective at communication since
they deliver their comments to the user
without any knowledge of the user's
"intent" for a sentence.
Compiler Errors(cont..)
Since no user has a perfect knowledge of syntax
and semantics, errors are inevitable.
Error Detection
Error Recovery.
1
Lexical Analyzer
2
Syntax Analyzer
3
Semantic Analyzer
5
Code Optimizer
6
Code Generator
Target Program
Types Errors
There are five types of errors:
1. Lexical Errors.
2. Syntax Errors.
3. Semantic Errors.
4. Logical Errors.
5. Spurious Errors.
Note:
The first three types of errors are
handle by error handler.
9
Lexical Errors
When the remaining characters in the input do
not found a valid token then it is called lexical
errors.
For example
Example:
Consider the sentence A B
The sentence requires an operator (+) between the 2 letters.
The compiler message might be Missing operator
Syntax Errors (cont…)
Example 2:
Consider the sentence A+B+
This sentence is not valid.
The reason for the rejection is an error in the
input sentence.
The sentence needs another letter at the end.
The compiler message might appear as
follows:
program.cpp(5) error c2059: Missing operand
^^file name.................^^the compiler's
explanation
............^^line number within the file
Syntax Errors (cont…)
What the compiler thinks is that you meant to type another
letter.
In the world of compilers, the "things" that you add are
termed "operands"; thus, the error message "missing
operand".
However, it is just as likely that you made a mistake typing
the extra "+".
The conclusion is that the message may, or may not, help
you.
The best plan is to use the point of error (line 5) as the
starting point to determine which syntax or semantic rule
has been violated.
3. Semantic Errors
When the operation of source program are not
meaningful.
Remember that a semantic error is a rule
violation that has nothing to do with syntax
diagrams.
For example, numbers in a computer are
normally restricted to a maximum number of
digits.
If you type too many digits 871239817231723178,
you will get a semantics-based error message.
Example
thanks