1 / 13

CSCI 2670 Introduction to Theory of Computing

CSCI 2670 Introduction to Theory of Computing. September 14, 2005. Agenda. Yesterday Pumping lemma Today Introduce context-free grammars Formally define CFG’s Begin designing CFG’s Tomorrow More on designing CFG’s Chomsky normal form. Announcement. Quiz tomorrow Regular expressions

daria
Download Presentation

CSCI 2670 Introduction to Theory of Computing

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. CSCI 2670Introduction to Theory of Computing September 14, 2005

  2. Agenda • Yesterday • Pumping lemma • Today • Introduce context-free grammars • Formally define CFG’s • Begin designing CFG’s • Tomorrow • More on designing CFG’s • Chomsky normal form

  3. Announcement • Quiz tomorrow • Regular expressions • Pumping lemma

  4. Context-free grammars • The shortcoming of finite automata is that each state has very limited meaning • You have no memory of where you’ve been – only knowledge of where you are • Context-free grammars are a more powerful method of describing languages • Example: {0n1n | n  0} is a CFG

  5. Example CFG • Context-free grammars use substitution to maintain knowledge S  (S) S  SS S  () • All possible legal parenthesis pairings can be expressed by consecutive applications of these rules • Is this a regular language?

  6. Example S  (S) | SS | () • (()())(()) • S  SS  (S)(S)  (SS)(())  (()())(()) • This sequence of substitutions is called a derivation

  7. S S S S S S ( () () ) ( () ) Parse tree S  (S) | SS | () S

  8. Example 2 S  Sb | Bb B  aBb | aCb C  ε • Derivation for aaabbbbb SSb Bbb aaBbbbb aaaεbbbbb aBbbb aaaCbbbbb

  9. S B B B C a a a ε b b b b b Example 2 parse tree S

  10. Example 2 S  Sb | Bb B  aBb | aCb C  ε Question 1: What language does this grammar accept? Answer: {anbm | m > n > 0} Question 2: Can this CFG be simplified? Answer: yes. Replace BaCb with Bab and remove Cε

  11. Context-free grammar definition • A context-free grammar is a 4-tuple (V,,R,S), where • V is a finite set called the variables, •  is a finite set, disjoint from V, called the terminals, • R is a finite set of rules, with each rule being a variable and a string of variables and terminals, and • S  V is the start variable.

  12. More definitions • If u, v, and w are strings of variables and terminals, and A  w is a rule of the grammar, we say uAv yields uwv • Denoted uAv  uwv

  13. More definitions • If a sequence of rules leads from u to v – i.e., u  u1  u2  …  v, we denote this u * v • (I can’t do the actual notation in powerpoint – the * should be over the double bars) • The language of the grammar is {w  * | s * w}

More Related