6Viable-Prefix Property. The viable-prefix property of parsers allowsearly detection of syntax errors- Goal: detection of an error as soon as possiblewithout further consuming unnecessary input- How: detect an error as soon as the prefix of theinputdoesnotmatchaprefixofanystringinthe languageErrorisErrorisdetected heredetectedherePrefixPrefixDO10I=1;0for(;)
SError Recovery Strategies. Panic mode- Discard input until a token in a set of designatedsynchronizingtokensisfound.Phrase-level recovery- Performlocal correction on the input to repair the errorErrorproductions- Augment grammar with productions for erroneousconstructs. Global correction- Choose a minimal sequence of changes to obtain agloballeast-costcorrection
8Grammars (Recap). Context-free grammar is a 4-tupleG = (N, T, P, S) where-Tis a finite set of tokens (terminal symbols)-Nis a finite set of nonterminals-Pisafinitesetofproductionsof theformα→βwhere α E(NUT* N(NUT)*and β E(NUT)*- SE Nis a designated start symbol
9Notational Conventions Used· Terminalsa,b,c....ETspecific terminals: 0, 1, id, +NonterminalsA.B.C.... ENspecific nonterminals: expr, term, stmtGrammarsymbolsX,Y,ZE (NUT)Stringsofterminalsu,v,w,x,y,zeT*Stringsofgrammarsymbolsα,β,E (NUT)*
10Derivations (Recap). The one-step derivation is defined byαAβ=→αβwhere A → is a production in the grammarInaddition,wedefine- → is leftmost =im if α does not contain a nonterminal→isrightmost=mifβdoesnotcontainanonterminal-Transitiveclosure=*(zeroormoresteps)-Positiveclosure=+(oneormoresteps): The language generated by G is defined byL(G) = (wE T* IS =+w)