1 / 21

Context-free Grammars

Context-free Grammars. Recursive definition Grammar Derivation. What is the syntax of the description (meta-language)? External form of the grammar How do we associate a language with such a description? Semantics or use of the grammar

kamal
Download Presentation

Context-free Grammars

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 Grammars L4CFG

  2. Recursive definition • Grammar • Derivation L4CFG

  3. What is the syntax of the description (meta-language)? • External form of the grammar • How do we associate a language with such a description? • Semantics or use of the grammar • Generators: Grammars specify languages by generating strings in the language. • Recognizers: Grammars can be viewed as a notation for describing a family of recognition algorithms. L4CFG

  4. CFG = (V, ,P,S) • V : Finite set of variables/non-terminals • : Alphabet/Finite set of terminals • P : Finite set of rules/productions • S : Start symbol L4CFG

  5. a* represents a context-free language because we can write a CFG for it. • A-rule, null-rule, -rule. • Context-freeness: An A-rule can be applied whenever A occurs in a string, irrespective of the context (that is, non-terminals and terminals around A). • Cf. context-sensitive grammar (“declare-use”) L4CFG

  6. From CFG to Language • One-step Derivation (Defn: 3.1.2) • w is derivable from v in CFG, if there is a finite sequence of rule applications such that: L4CFG

  7. Let G=(V, S, P, S) be a CFG. • is a sentential form, if . • is a sentence, if . • The language of G, L(G) = L4CFG

  8. S S a a b b • Derivation of aabb • Derivation tree l L4CFG

  9. L4CFG

  10. Derivation Tree (abstracts derivation) S A B A B b a l l L4CFG

  11. Examples: CFGs and CFLs L4CFG

  12. L4CFG

  13. Note that parentheses are part of the meta-language. L4CFG

  14. L4CFG

  15. L4CFG

  16. Left to right generation of string. L4CFG

  17. Regular Grammar • A regular grammar is a CFG in which each of the rules has the form: (Right Linear Grammar) L4CFG

  18. Equivalent Regular Grammar • A regular grammar is a CFG in which each of the rules has the form: (Left Linear Grammar) L4CFG

  19. L4CFG

  20. L4CFG

  21. Derivations Note that the above result does not hold for sentential forms. L4CFG

More Related