1 / 76

Context-Free Languages

Context-Free Languages. Regular Languages. Context-Free Languages. Regular Languages. Context-Free Languages. Context-Free Grammars. Pushdown Automata. stack. automaton. Context-Free Grammars. Example. A context-free grammar :. A derivation:. A context-free grammar :.

jlancaster
Download Presentation

Context-Free Languages

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. Context-Free Languages COMP 335

  2. Regular Languages COMP 335

  3. Context-Free Languages Regular Languages COMP 335

  4. Context-Free Languages Context-Free Grammars Pushdown Automata stack automaton COMP 335

  5. Context-Free Grammars COMP 335

  6. Example A context-free grammar : A derivation: COMP 335

  7. A context-free grammar : Another derivation: COMP 335

  8. (((( )))) Describes parentheses: COMP 335

  9. Example A context-free grammar : A derivation: COMP 335

  10. A context-free grammar : Another derivation: COMP 335

  11. COMP 335

  12. Example A context-free grammar : A derivation: COMP 335

  13. A context-free grammar : A derivation: COMP 335

  14. Describes matched parentheses: () ((( ))) (( )) COMP 335

  15. Definition: Context-Free Grammars Grammar Variables Terminal symbols Start variable Productions of the form: Variable String of variables and terminals COMP 335

  16. COMP 335

  17. Definition: Context-Free Languages • A language is context-free • if and only if • there is a context-freegrammar • with COMP 335

  18. Leftmost derivation: Rightmost derivation: Derivation Order COMP 335

  19. Leftmost derivation: Rightmost derivation: COMP 335

  20. Derivation Trees COMP 335

  21. COMP 335

  22. COMP 335

  23. COMP 335

  24. COMP 335

  25. Derivation Tree COMP 335

  26. Derivation Tree yield COMP 335

  27. Partial Derivation Trees Partial derivation tree COMP 335

  28. Partial derivation tree COMP 335

  29. sentential form Partial derivation tree yield COMP 335

  30. Sometimes, derivation order doesn’t matter Leftmost: Rightmost: Same derivation tree COMP 335

  31. So far, we concentrated on generative aspect of grammars.How about analytical aspect?Parsing….. COMP 335

  32. Parser input string derivation grammar COMP 335

  33. Example: Parser derivation input ? COMP 335

  34. Exhaustive Search Phase 1: Find derivation of All possible derivations of length 1 COMP 335

  35. COMP 335

  36. Phase 2 Phase 1 COMP 335

  37. Phase 2 Phase 3 COMP 335

  38. Final result of exhaustive search (top-down parsing) Parser input derivation COMP 335

  39. Time complexity of exhaustive search Suppose there are no productions of the form Number of phases for string is Why? COMP 335

  40. For grammar with rules Time for phase 1: possible derivations COMP 335

  41. Time for phase 2: possible derivations COMP 335

  42. Time for phase : possible derivations: which is exponential in the length of w COMP 335

  43. Total time needed for parsing : phase 1 phase 2|w| phase 2 Extremely bad!!! COMP 335

  44. There exist faster algorithms for specialized grammars S-grammar: symbol string of variables appears once Pair COMP 335

  45. S-grammar example: Each string has a unique derivation COMP 335

  46. For S-grammars: In the exhaustive search parsing there is only one choice in each phase Time for a phase: Total time for parsing string : COMP 335

  47. For general context-free grammars: There exists a parsing algorithm that parses a string in time (we will show it in the next class) COMP 335

  48. Ambiguity COMP 335

  49. leftmost derivation COMP 335

  50. leftmost derivation COMP 335

More Related