Error recovery is about ignoring tokens. ▪ How do we know which tokens should be ignored and how many? RULE What should be in place for me to enter? What should be in place for me to leave?
Error Recovery Rule FIRST set FOLLOW set PROGRAM { EOF BODY FIRST (PRINT) U FIRST (ASIGNMENT) U FIRST(VARIABLE) U FIRST (WHILE) U FIRST(IF) U FIRST (RETURN) } PRINT print ; ASSIGNMENT identifier ; VARIABLE int, float, boolean, void, char, string ; WHILE while } U FIRST(BODY) IF if } U FIRST(BODY) RETURN return ; EXPRESSION FIRST(X) ), ; X FIRST(Y) | U FOLLOW(EXPRESSION) Y ! U FIRST(R) & U FOLLOW(X) R FIRST(E) FOLLOW(Y) E FIRST (A) !=, ==, >, < U FOLLOW(R) A FIRST (B) -, + U FOLLOW(E) B - U FIRST (C) *, /, U FOLLOW(A) C integer, octal, hexadecimal, binary, true, false, string, char, float, identifier, ( FOLLOW(B)
Definition FIRST (a) is the set of tokens that can begin the construction a. Example <E> → <A> {+ <A>} <A> → <B> {* <B>} <B> → -<C> | <C> <C> → integer FIRST(E) = {-, integer} FIRST(A) = {-, integer} FIRST(B) = {-, integer} FIRST(C) = {integer}
S → ABC S → F A → EFd A → a B → aBb B → ε C → cC C → d E → eE E → F F → Ff F → ε rule FIRST set - evolution S ø {a, ε} {a, ε, e, f} {a, ε, e, f, d} A ø {a} {a, e} {a, e, f, d} B ø {a, ε} C ø {c, d} E ø {e} {e, ε} {e, ε, f} F ø {ε} {ε, f}
slides can only be used as study material for the Compilers course at Universidad Panamericana. They cannot be distributed or used for another purpose.