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 productionsCS453 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 Add minimal overhead to the processing of correct programs Find “all” errors in program before translation beginsCS453 Lecture Error Recovery II 3Predictive parser for Float Assignment Grammarvoid S() { switch (lookahead) { case ID: case EOF:// the 2 tokens in the FIRST(StmList EOF)try { StmList(); match(EOF); } catch { panic(S); } break; default: panic(S); break;}}void StmList() { switch (lookahead) { case ID: // FIRST( Stm StmList ) = { ID } try { Stm(); StmList(); } catch { panic(StmList) } break; case EOF: // FOLLOW(StmList) = { EOF } break; default: panic(StmList); break;}}void Stm() { switch (lookahead) { case ID: try { match(ID); match(ASSIGN); match(FLOAT); } catch { panic(Stm); } break; default: panic(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 from Tiger Book)LES$)(:=+,;printnumidr8r815s13s1914r3r3r313s18s312r2s16r2r211r5r5r5r5r510g14g15s8s10s209g12s7s48s97g11s8s10s206r1r1r15s64g5s7s43as32g2s7s41CS453 Lecture Error Recovery II 6LR parse table (Table 3.19 from Tiger book) 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 Show the Stack, Input, and Action table (see Figure 3.18 in handout)using the parse table on slides 5 and 6 where the parser is using panicmode recovery for the following inputs:= b + c - ; $( d := 5 + 6, 3 ) $( ( ) )
View Full Document