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

Syntax Error Handling-1

The document discusses syntax error handling. The main tasks of syntax error handling are to detect errors, report them to the user, and implement recovery strategies without slowing down program processing time. There are four main types of errors: lexical, syntactic, semantic, and logical. Common error handling techniques include panic mode, phrase level recovery, error productions, and global correction. Panic mode discards tokens until a delimiter is found. Phrase level recovery inserts missing tokens to allow parsing to continue locally. Error productions augment the grammar to recognize common errors. Global correction finds a minimally changed parse tree that parses the input.

Uploaded by

Aarthi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Syntax Error Handling-1

The document discusses syntax error handling. The main tasks of syntax error handling are to detect errors, report them to the user, and implement recovery strategies without slowing down program processing time. There are four main types of errors: lexical, syntactic, semantic, and logical. Common error handling techniques include panic mode, phrase level recovery, error productions, and global correction. Panic mode discards tokens until a delimiter is found. Phrase level recovery inserts missing tokens to allow parsing to continue locally. Error productions augment the grammar to recognize common errors. Global correction finds a minimally changed parse tree that parses the input.

Uploaded by

Aarthi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

SYNTAX ERROR

HANDLING
Presented By:
D.Gokul Raja(61072111114)
V.Gokul(61072111113)
Syntax error handling

The tasks of the Syntax Error Handling process


are to detect each error, report it to the user, and
then make some recovery strategy and implement
them to handle the error. During this whole process
processing time of the program should not be slow.
SYNTAX ANALYSIS

• The main features of syntax analysis, which is done by parser, are


as follows:
Grammar
Parse tree production
Output errors
Types of Error
• There are mainly four types of error. They are as follows: There are
mainly four types of error. They are as follows:
• Lexical Error : Such as misspelling an identifier, keyword or operator.
• Syntactic Error : Such as an arithmetic expression with unbalanced
parentheses.
• Semantic Error : Such as operator applied to an incompatible
operand.
• Logical Error : Such as infinitely recursive call.
ERROR HANDLING
TECHNIQUES

• Panic mode
• Phrase level recovery
• Error production
• Global correction
• 1. Panic Mode
• In case of an error like:
• a=b + c // no semi-colon
• d=e + f ; d=e + f ;
• The compiler will discard all subsequent tokens till a semi-colon is
encountered.
• This is a crude method but often turns out to be the best method.

• In situations where multiple errors in the same statements are rare,


this method may be quite adequate.
2. Phrase Level Recovery

• On discovering an error, a parser may perform local correction on


the remaining input; that is, it may replace a prefix of the
remaining input by some string that allows the parser to continue.
• For example, in case of an error like the one above, it will report
the error, generate the “;” and continue.
3. Error Production

• If we have good knowledge of common errors that might be


encountered, then we can augment the grammar for the
corresponding language with error productions that generate the
erroneous constructs,
• If error production is used during parsing, we can generate
appropriate error message to indicate the erroneous construct
that has been recognized in the input.
• This method is extremely difficult to maintain, because
if we change grammar then it becomes necessary to
change the corresponding productions.
• For Example: suppose the input string is abed
• Grammar:
E->SB
S->A
A->aA|bA|a|b
B->cd

4. Global Correction
• We often want such a compiler that makes very few changes in
processing an incorrect input string.
• Given an incorrect input string & and grammar G, the algorithm
will find a parse tree for a related string y, such that number of
insertions, deletions and changes of token require transform x into
y is as small as possible.
• Such methods increase time and space requirements at parsing
time.
• Global production is thus simply a theoretical concept.
T H A N K Y O U..

You might also like