DOC PREVIEW
CSU CS 453 - Study Guide

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS453 Intro and PA1 1CS453 Lecture Error Recovery II 1Plan for Today Error recovery goals Review panic mode error recovery for predictive parsers Panic mode for LR parsers Error recovery using error symbol in productions– available in YACC Lines and positions information– in general how could it be improved?– can we actually implement such improvements with SableCC? Where should an overflow number error be handled?CS453 Lecture Error Recovery II 2Error Handling Goals Provide program with a list of as many errors as possible Provide USEFUL error messages– appropriate line and position information– guidance for fixing the error Avoid infinite loops or recursion Find “all” errors in program before translation beginsCS453 Lecture Error Recovery II 3Predictive parser using panic mode error recoveryeat(tok) { if (tok==t) advance(); else throw ...; }panic(tokset) { while (getToken() not in tokset) ; }advance() { tok = getToken(); }void S() { switch (tok) { case ID: case EOF:try { StmList(); } catch { panic(FOLLOW(StmList)); } eat(EOF); break; default: print "error"; panic(FOLLOW(S)); break;}}void StmList() { switch (tok) { case ID: try { Stm(); } catch { panic(FOLLOW(Stm)); } try { StmList(); } catch { panic(FOLLOW(StmList)); } break; case EOF: break; default:print "error"; panic(FOLLOW(StmList)); break;}}void Stm() { switch (tok) { case ID: eat(id); eat(assign); eat(float); break; default: print "error"; panic(FOLLOW(Stm)); break;}}CS453 Lecture Error Recovery II 4Grammar 3.1 from Tiger book(0) S’ -> S $(1)S -> S ; S(2)S -> id := E(3)S -> print (L)(4)E -> id(5)E -> num(6)E -> E + E(7)E -> (S,E)(8)L -> E(9)L -> L, ECS453 Intro and PA1 2CS453 Lecture Error Recovery II 5LR parse table (Table 3.19)LES$)(:=+,;printnumidr8r815s13s1914r3r3r313s18s312r2s16r2r211r5r5r5r5r510g14g15s8s10s209g12s7s48s97g11s8s10s206r1r1r15s64g5s7s43as32g2s7s41CS453 Lecture Error Recovery II 6LR parse table (Table 3.19) cont...LES$)(:=+,;printnumidr9s16r923r7r7r7r7r722s2221r4r4r4r4r420g23s8s10s2019g21s8s10s2018r6r6s16r6r617g17s8s10s2016CS453 Lecture Error Recovery II 7Error recovery using an error symbolSteps taken when error occurs(0) generate error indicating expected token(s)(1) pop off stack until have state with shift action for error token(2) shift the error token(3) throw away input tokens until hit token with non-error action(4) resume parsingexp -> ( error )exps -> error ; expCS453 Lecture Error Recovery II 8Suggested Exercises Write a predictive parser using panic mode error recovery for thegrammar shown below. Show the Stack, Input, and Action table (see Figure 3.18) using the parsetable in Figure 3.19 where the parser is using panic mode recovery for thefollowing inputs:= b + c - ; $( d := 5 + 6, 3 ) $( ( ) ) $(0) S -> E $(1) E -> B E’(2) E’ -> ‘or’ B E’(3) E’ ->(4) B -> t |


View Full Document

CSU CS 453 - Study Guide

Download Study Guide
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Guide and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Guide 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?