Ticker

6/recent/ticker-posts

Error recovery in LL(1) parsing



Programmers and human beings who generally make programming mistakes.The incorrect program written by programmer contains error.

Error handing is a part of compilation process.Error detection and its reporting is important function of compiler.

Goals of error Handler

  • Error message should be easy to understand by the user.
  • Error message should be in the form of source program rather than in some internal representation.
  • Error message should locate the line number at which error has occurred.
Syntactic phase error
Error detected during syntax analysis phase are syntactic phase error.When structure of statements violates rules of programming language.
Syntactic error just like
  • Missing parenthesis.
  • Missing semicolon.
  • Missing keyword.
Error recovery in LL(1) parser
It performs the least number of insertions and deletions and symbol modifications necessary to change incorrect program to correct or legal program.

For Example
Consider the grammar
E->TE'
E'->+TE'|∊
T->FT'
T'->*FT'|∊
F->(E)|id
Detect and recover error using LL(1) parsing.

Solution

First computation of FIRST and FOLLOW for different symbols of grammar.
FIRST of  E=FIRST OF T=FIRST of F={(,id}
FIRST of E'={+,∊}
FIRST of T=FIRST of F={(,id}
FIRST of T'={*,∊}
FIRST of F={(,id}

FOLLOW of E={),$}
FOLLOW of E'=FOLLOW  of E={),$}
FOLLOW of T=FIRST of E'={+}
and put the value of ∊in place of E'
FOLLOW OF E={),$}
so FOLLOW of  T={),+,$}
FOLLOW of T'=FOLLOW of T={),+$}
FOLLOW of F=FIRST of T'={*,∊}
put the value of T'=∊
So FOLLOW of F=FOLLOW of T
So FOLLOW of F={*,+,),$)

Then create the LL parsing table for the grammar with error entries


POP
POP entries in the table will be executed when the symbol at top of stack is same as current input symbol.

Error e1
It occurs when input string begins with any operator +,*,) and when end of input occurs with $.
Recovery
Push id onto input.(Missing operand)

Error  e2
It occurs when top of stack contain right parenthesis but input string does not contain it.
Recovery
Pop right parenthesis from stack.(Missing right parenthesis)

Error e3
It occurs when stack is empty but there is still input symbol left on input string.
Recovery
Remove remaining symbols from input string.(Unexpected input symbol.)

Example
Detect and correct error on input  id+)  LL parsing and grammar is 
 E->TE'
E'->+TE'|∊
T->FT'
T'->*FT'|∊
F->(E)|id




So LL(1) parser accept and correct input string  id+) .




 


Post a Comment

0 Comments