1 / 82

Context-Free Languages Hinrich Sch ütze CIS, LMU, 2013-11-25 Slides based on RPI CSCI 2400

Learn about context-free grammars, derivation trees, ambiguity, and how context-free grammars describe natural languages. Understand the notation and language of context-free grammars.

mattice
Download Presentation

Context-Free Languages Hinrich Sch ütze CIS, LMU, 2013-11-25 Slides based on RPI CSCI 2400

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 Hinrich Schütze CIS, LMU, 2013-11-25 Slides based on RPI CSCI 2400 Thanks to Costas Busch

  2. Take-away • Definition context-free grammar • Definition context-free language • Derivation, sentential form, sentence • Derivation trees • Ambiguity • Context-free grammars for natural language

  3. Terminology • For our purposes in this class: • Context free grammar • = • Constituency grammar • = • Phrase structure grammar

  4. Grammars • Grammars express languages • Example: the English language

  5. A derivation of “the dog walks”:

  6. A derivation of “a cat runs”:

  7. Language of the grammar: L = { “a cat runs”, “a cat walks”, “the cat runs”, “the cat walks”, “a dog runs”, “a dog walks”, “the dog runs”, “the dog walks” }

  8. Notation Production Rules Variable Terminal

  9. Another Example • Grammar: • Derivation of sentence :

  10. Language?

  11. Grammar: • Derivation of sentence :

  12. Other derivations:

  13. Language of the grammar

  14. More Notation • Grammar Set of variables Set of terminal symbols Start variable Set of Production rules

  15. Example • Grammar :

  16. More Notation • Sentential Form: • A sentence that contains • variables and terminals • Example: Sentential Forms sentence

  17. We write: • Instead of:

  18. In general we write: • If:

  19. By default:

  20. Example Grammar Derivations

  21. Example Grammar Derivations

  22. Another Grammar Example • Grammar :

  23. Language?

  24. Grammar : Derivations:

  25. More Derivations

  26. Language of a Grammar • For a grammar • with start variable : String of terminals

  27. Example • For grammar : Since:

  28. A Convenient Notation

  29. Revisit first grammar A context-free grammar : A derivation:

  30. A context-free grammar : Another derivation:

  31. (((( )))) Describes parentheses:

  32. Example A context-free grammar :

  33. Language?

  34. A context-free grammar : Another derivation:

  35. Example A context-free grammar :

  36. Language?

  37. A context-free grammar : Two derivations:

  38. Interpretation?

  39. Describes matched parentheses: () ((( ))) (( ))

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

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

  42. Leftmost derivation: Rightmost derivation: Derivation Order

  43. Language?

  44. Leftmost derivation: Rightmost derivation:

  45. Language?

  46. Derivation Trees

More Related