lectures 7 and 8 parsing syntax analysis
play

Lectures 7 and 8. Parsing (syntax analysis) Wei Le 2015.9 Bottom - PowerPoint PPT Presentation

Lectures 7 and 8. Parsing (syntax analysis) Wei Le 2015.9 Bottom Up Parsing Recognize many programming languages, used in practice More general, more powerful parser: less restrictions on grammars, e.g., can handle left-recursive grammar


  1. Lectures 7 and 8. Parsing (syntax analysis) Wei Le 2015.9

  2. Bottom Up Parsing ◮ Recognize many programming languages, used in practice ◮ More general, more powerful parser: less restrictions on grammars, e.g., can handle left-recursive grammar ◮ no backtracking ◮ LR parsing: L – tokens are read from the left to right, R – rightmost derivation ◮ LR parsing reduces a string to the start symbol by inverting productions

  3. LR Parsing

  4. LR Parsing: An Example

  5. LR Parsing: An Example

  6. LR Parsing: An Example

  7. LR Parsing: An Example

  8. LR Parsing: An Example

  9. LR Parsing: An Example

  10. LR Parsing: Important Factor #1

  11. LR Parsing: Where Reduction Happens

  12. LR Parsing: Split Notation

  13. LR Parsing: Shift and Reduce

  14. Shift and Reduce Example

  15. Shift and Reduce Example

  16. Shift and Reduce Example

  17. Shift and Reduce Example

  18. Shift and Reduce Example

  19. Shift and Reduce Example

  20. Shift and Reduce Example

  21. Shift and Reduce Example

  22. Shift and Reduce Example

  23. Shift and Reduce Example

  24. Shift and Reduce Example

  25. The stack

  26. Key issues: when to shift or reduce

  27. Key issues: when to shift or reduce

  28. LR Parsing Algorithm

  29. Parsing Table

  30. Parsing Table

  31. Table-Driven Bottom Up Parsing

  32. LR Parsing Algorithm

  33. Review: Key Ideas of LR Parsing

  34. Review: Key Ideas of LR Parsing

  35. How to Decide When to Shift or Reduce

  36. How to Construct the Parsing Table Run stack on DFA: search which context matches the stack?

  37. LR(1) Item Defines the State (or Context)

  38. Notation Clarification

  39. LR(1) Items Are Used to Define DFA

  40. LR(1) Items Are Used to Define DFA: An Example

  41. LR(1) Items Are Used to Define DFA: An Example

  42. How To Determine a set of LR(1) Items for the State?

  43. Closure Operation: An Example

  44. Closure Operation: An Example

  45. Closure Operation: An Example

  46. LR(1) Items Are Used to Define DFA: An Example

  47. LR(1) Items Are Used to Define DFA: Transitions

  48. Automatically Generating Parsing Tables

  49. Shift and Reduce Conflict

  50. Shift and Reduce Conflict

  51. Shift and Reduce Conflict

  52. Shift and Reduce Conflict

  53. Reduce Reduce Conflict

  54. Reduce Reduce Conflict

  55. Reduce Reduce Conflict

  56. Motivation of LALR

  57. Motivation of LALR

  58. Motivation of LALR

  59. LALR

  60. LALR

  61. LALR: Example

  62. LALR

  63. LALR

  64. Parsing: A Summary ◮ Parse tree: how to derive a string from the grammar ◮ Context free grammars ◮ Algorithms: Recursive Decedent Parsers, LL (1), LR (1), LALR (1) ◮ General approach: table-driven parsing (the stack, streams of tokens, general parsing algorithm), using table to guide each step of building parsing trees ◮ Challenge: Building parsing table

Recommend


More recommend