1 / 25

Errors in Top-Down Parsing

Errors in Top-Down Parsing. Teoría de Autómatas y Lenguajes Formales M. Luisa González Díaz Universidad de Valladolid, 2005. type → simple | ^ simple | array [ simple ] of type simple → integer | char | num ptpt num.

kswan
Download Presentation

Errors in Top-Down Parsing

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. Errors in Top-Down Parsing Teoría de Autómatas y Lenguajes Formales M. Luisa González Díaz Universidad de Valladolid, 2005

  2. type → simple | ^ simple | array [simple] oftypesimple → integer | char | num ptpt num

  3. type → simple | ^ simple | array [simple] oftype simple → integer | char | num ptpt num A correct input: array [ char ] of integer

  4. array [ simple ] of type simple char integer type → simple | ^ simple | array [simple] oftype simple → integer | char | num ptpt num type $ array [ char ] of integer $ Lex. An.

  5. Empty entries

  6. type → simple | ^ simple | array [simple] oftype simple → integer | char | num ptpt num type $ array [ simple ] of type array Lex. An.

  7. type → simple | ^ simple | array [simple] oftype simple → integer | char | num ptpt num type $ array [ simple ] of type array [ ^ Lex. An.

  8. type → simple | ^ simple | array [simple] oftype simple → integer | char | num ptpt num type $ array [ simple ] of type array [ ^ char Lex. An. Error

  9. simple char integer type → simple | ^ simple | array [simple] oftype simple → integer | char | num ptpt num type $ array [ simple ] of type array [ ^ char ] of integer $ Lex. An.

  10. Other kind of empty entries

  11. type → simple | ^ simple | array [simple] oftype simple → integer | char | num ptpt num type $ array [ simple ] of type array Lex. An.

  12. char type → simple | ^ simple | array [simple] oftype simple → integer | char | num ptpt num type $ array [ simple ] of type array [ type char ] of $ Lex. An. Error

  13. type → simple | ^ simple | array [simple] oftype simple → integer | char | num ptpt num Panic mode Unexpected token: Mark error. Try again with the next token Unexpected end of string: Mark error. Recognize we can’t expand non terminal

  14. Code (panic mode) proceduretype; if lookahead = array then match(array); match (‘[‘);simple; match(‘]‘); match(of); type else if lookahead = ‘^’ then match(‘^’); simple else if lookahead in {char, integer, num} then simple else if lookahead in {‘[‘,of, ‘]’} then writeln (‘Error:unexpected’, lookahead); match (lookahead); type else (* lookahead = $ *) writeln (‘Error: I couldn’t find type’) normal errors

  15. Match errors

  16. array [ simple ] of type simple char integer type → simple | ^ simple | array [simple] oftype simple → integer | char | num ptpt num type $ array [ char char ] of integer $ Lex. An. Error

  17. Other kind of match errors

  18. array type → simple | ^ simple | array [simple] oftype simple → integer | char | num ptpt num type $ [ simple ] of type array $ Lex. An. Error

  19. match: panic mode • lookahead = expected token (t) • OK: read next token into lookahead and return • lookahead <> expected token (t) • mark error :unexpected token (t), but • lookahead <> $ • try again with the next token into lookahead • lookahead = $ • don’t try again, don’t read anymore, just return

  20. Code of match (panic mode) procedure match (t: token); (*Pre: t <> $ * Never try to match end of string) begin if lookahead = t then lookahead := nexttoken (lexical analyzer) else if lookahead <> $ then writeln (‘Unexpected’, lookahead); lookahead := nexttoken; match (t) else (* lookahead = $ *) writeln (‘Unexpected end of string’) end

  21. array type → simple | ^ simple | array [simple] oftype simple → integer | char | num ptpt num type $ [ simple ] of type array [ simple ] of type $ Lex. An. Error Error Error Error Error

  22. Main program Begin lookahead = nexttoken; type; if lookahead = $ then input finished (errors, if any, were marked) else unexpected input after end of type End.

  23. type → simple | ^ simple | array [simple] oftypesimple → integer | char | num ptpt num An example of phrase-level error-recovery strategy Suposse it’s quite usual forgeting first number in num ptpt num Error action : mark it was forgotten

  24. normal errors Code (panic+phrase-level mode) proceduresimple; if lookahead = integer then match(integer); else if lookahead = char then match(char); else if lookahead = num then match(num); match(ptpt); match(num); else if lookahead in {array, ‘^’, ‘[‘, of, ‘]’} then writeln (‘Error:unexpected’, lookahead); match (lookahead); simple else if lookahead = ptptthen writeln (‘Error: forgotten num’); match(ptpt); match(num); else (* lookahead = $ *) writeln (‘Error: I couldn’t find simple’)

More Related