error recovery l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Error Recovery PowerPoint Presentation
Download Presentation
Error Recovery

Loading in 2 Seconds...

play fullscreen
1 / 8

Error Recovery - PowerPoint PPT Presentation


  • 141 Views
  • Uploaded on

Error Recovery. CS 671 February 5, 2008. Previously. Top-Down Parsing, e.g. LL(1) Bottom-Up Parsing, e.g. LR(1) Next Question : What if the compiler finds a syntactic error?. Error Recovery. What if the compiler finds a syntactic error? Ideally, report all errors, not just first

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Error Recovery' - eileen


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
error recovery

Error Recovery

CS 671

February 5, 2008

previously
Previously
  • Top-Down Parsing, e.g. LL(1)
  • Bottom-Up Parsing, e.g. LR(1)
  • Next Question:
  • What if the compiler finds a syntactic error?
error recovery3
Error Recovery
  • What if the compiler finds a syntactic error?
  • Ideally, report all errors, not just first
  • Approaches:
  • Local error recovery – Find synch point, resume
  • Global error recovery – Change input, resume
local error recovery
Local Error Recovery
  • Informally, skip to next synchronizing token
  • Example

exp  ID

exp  exp + exp

exp  ( exps )

exps  exp

exps  exps ; exp

    • Skip to next SEMICOLON or RPAREN
    • Resume parsing

How?Introduce new terminal symbols and rules:

exp  ( error )

exps  error ; exp

caution
Caution…
  • Unfortunately, error states can cause problems when semantic actions are attached (unless we’re careful). Consider:
  • statements : statements exp SEMICOLON
  • | statements error SEMICOLON
  • | /* empty */
  • exp : increment exp decrement
  • | ID
  • increment: LPAREN {nest=nest+1;}
  • increment: RPAREN {nest=nest-1;}
global error repair
Global Error Repair
  • Another way to recover: insert/delete tokens before the point of the error
  • let type a := intArray [ 10 ] of 0 in …
  • ^
  • (real error: type should be var)
  • Global repair: Find smallest set of insertions or deletions that would convert string to a syntactically correct string (not always at error point)
  • Outcome: type  var (1 replacement)
burke fisher error repair
Burke-Fisher Error Repair
  • Tries every possible single-token insertion, deletion, replacement up to K tokens before error.
  • Chooses: Whichever replacement, etc. allows it to progress farthest after error
  • Realistic limit: 4 tokens beyond error is “good enough”

error

K

yacc support for error correction
Yacc Support for Error Correction
  • The %value directive (used during insertions)
  • %value ID (“bogus”)
  • %value INT (1)
  • %value STRING (“”)
  • Programmer specified substitutions
  • %change EQ -> ASSIGN |
  • ASSIGN -> EQ |
  • SEMICOLON ELSE -> ELSE |
  • -> RBRACE

Scope closer