1 / 8

Error Recovery

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

eileen
Télécharger la présentation

Error Recovery

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Error Recovery CS 671 February 5, 2008

  2. 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?

  3. 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

  4. 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

  5. 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;}

  6. 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)

  7. 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

  8. 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

More Related