1 / 18

CSI 3104 /Winter 2006 : Introduction to Formal Languages Chapter 16: Non-Context-Free Languages

CSI 3104 /Winter 2006 : Introduction to Formal Languages Chapter 16: Non-Context-Free Languages. Chapter 16: Non-Context-Free Languages I. Theory of Automata  II. Theory of Formal Languages III. Theory of Turing Machines …. Chapter 16: Non-Context-Free Languages.

bond
Download Presentation

CSI 3104 /Winter 2006 : Introduction to Formal Languages Chapter 16: Non-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. CSI 3104 /Winter 2006: Introduction to Formal Languages Chapter 16: Non-Context-Free Languages Chapter 16: Non-Context-Free Languages I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines … Zaguia/Stojmenovic

  2. Chapter 16: Non-Context-Free Languages • Theorem. Let G be a context-free grammar in Chomsky normal form. Let L be the subset of words generated by G which have derivations such that each production of the form: Nonterminal  Nonterminal Nonterminal is used at most once. Then L is a finite set of words. Proof.At each step in a derivation, a nonterminal is replaced by either 2 nonterminals or one terminal. Thus, if there are p productions of the form: Nonterminal  Nonterminal Nonterminal a word in L contains at most p+1 letters. The set of words that contain at most p+1 letters is finite Zaguia/Stojmenovic

  3. Chapter 16: Non-Context-Free Languages Example: S  AB | a A  XY | a Y  SXX  a | b B b • S  AB  aB  ab • S  AB  XYB  bYB  bSXB  baXB  baaB  baab (1) (2) (3) • S  AB  XYB  XSXB  bSXB  baXB  baaB  baab (1) (2) (3) Zaguia/Stojmenovic

  4. S Z A a B B Z A … b S A A C B B B … b Chapter 16: Non-Context-Free Languages a branch: a path between the root and a leaf of a derivation tree S  AZ Z  BB B  ZA A  a B  b S  A Z  aZ  aBB abB  ab Z A… the same nonterminal twice on the same branch (The 2nd is a tree descendant of the 1st. The nonterminal is self-embedded.) S  AA A  BC C  BB A  a B  b S  AA  B CA  bCA b B BA… two different branches Remark: derivation trees are binary Zaguia/Stojmenovic

  5. Chapter 16: Non-Context-Free Languages • Theorem. Let G be a context-free grammar in Chomsky normal form that has p productions of the form: Nonterminal  Nonterminal Nonterminal. Let w be a word such that length(w)2p. Then in every derivation tree for w there exists some nonterminal Z that appears twice on the same branch. Zaguia/Stojmenovic

  6. S X Y A C B D X B C C A Y D A Chapter 16: Non-Context-Free Languages Example 1st raw 20 nodes 2nd raw 21 nodes 3rd raw 22 nodes 4th raw 23 nodes p=3 p+1 rows 2p leaves, maximum Zaguia/Stojmenovic

  7. p+1 nonterminals p nonterminals 1 terminal 1 terminal Chapter 16: Non-Context-Free Languages Proof. A tree that has more than 2p leaves has more than p+1 rows. (A tree that has p+1 rows has at most 2p leaves.) Zaguia/Stojmenovic

  8. S X Y B Y a S X X Y X a Y a X Y B Y b B Y b b a a b Chapter 16: Non-Context-Free Languages S  XY B  b X  BY X  a Y  XY Y  a B  SX Y  b • p=4 • the branch that ends in a has 6 nonterminals (5 applications of productions containing only nonterminals) • at least one production is used more than once Zaguia/Stojmenovic

  9. ………… 1st row S ……… 2nd row X A …… 3rd row a A S …… 4th row a X A …… 5th row S A a …… 6th row b a Chapter 16: Non-Context-Free Languages 26 = 64 Example: PALINDROME – {Λ} S  AX|BY|a|b|AA|BB X  SA Y  SB A  a B  b Zaguia/Stojmenovic

  10. S S X A X A a S A a A S a X A a X A A S a S A a a X A b a S A a b a Chapter 16: Non-Context-Free Languages aabaa aaabaaa Zaguia/Stojmenovic

  11. Chapter 16: Non-Context-Free Languages The pumping lemma (for context-free languages) Let G be a context-free grammar in Chomsky normal form that has p productions of the form: Nonterminal  Nonterminal Nonterminal. Let w be a word such that length(w)2p. Then w can be decomposed into 5 factors: w = uvxyzsuch that • x is not  • at least one of v and y is not  • for all n  1, uvnxynz is in the language generated by G. Zaguia/Stojmenovic

  12. S P u z Q P R v y x Chapter 16: Non-Context-Free Languages • Proof. From the previous theorem, there exists a non terminal P that occurs at least twice on the same branch. • w = uvxyz • x  L • either v  L, or y  L Zaguia/Stojmenovic

  13. S S A a S A a b Chapter 16: Non-Context-Free Languages • Note: u, z, and at least one of v and y could be L. • u = L v = L x = ba y = a z = L Zaguia/Stojmenovic

  14. S P S u z Q P R P v y u z Q Q P R P R v y v y Q Q P R P R v y v y x x Chapter 16: Non-Context-Free Languages uvvxyyz In general: uvnxynz uvvvxyyyz Zaguia/Stojmenovic

  15. S P u z Q P R v y x Algebraic proof • Alternatively: • S  uPz P  vPy P  x • S  uPz  uvPyz uvxyz = w • S  uPz  uvPyz uvvPyyz  uvvvPyyyz …  uvnxynz • w = uvxyz x  L • either v  L, or y  L means generated after several steps Zaguia/Stojmenovic

  16. START PUSH a ACCEPT a PUSH a D READ READ READ POP POP POP b b a D a a a Chapter 16: Non-Context-Free Languages anbnan? Zaguia/Stojmenovic

  17. anbnan is not context free language • p= # live productions:Nonterm.  Nonterm. Nonterm. • Let 3n > 2p by theorem w= anbnan = uvxyz • w contains exactly one abv and y have no ab • Similarly v and y have no ba • v=at or bt, y=aq or bq • v=at y=aq ? v=at y=bq ? v=bt, y=aq ? v=bt, y=bq ? • Problem: two out of three parts an bn an are growing, while the third part does not grow • But it supposed to be always of equal size … • Is anbncn a context free language ? Zaguia/Stojmenovic

  18. Length(vxy)  2p • More precise theorem: live production repeats already within length(vxy) up to 2p • Example: L={anbmanbm} is not context free • Proof: follow similar discussion, four parts: anbmanbm one case is: • v=at grows part 1, y=aq grows part 3 • but for m>2p this case does not exists in the more precise theorem  part imbalance Zaguia/Stojmenovic

More Related