1 / 25

CS 3240: Languages and Computation

CS 3240: Languages and Computation. Properties of Context-Free Languages. Properties of CFGs. Chomsky Normal Form. In Summary. Conversion to Chomsky Normal Form. q j. q 1. q k. Recall: Pumping Lemma for Regular Languages.

daria
Download Presentation

CS 3240: Languages and Computation

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. CS 3240: Languages and Computation Properties of Context-Free Languages

  2. Properties of CFGs

  3. Chomsky Normal Form

  4. In Summary

  5. Conversion to Chomsky Normal Form

  6. qj q1 qk Recall: Pumping Lemma for Regular Languages For every regular language L, there is a finite pumping length p, such that for any string sL and |s|p, we can write s=xyz with:1) x yi z  L for every i{0,1,2,…}2) |y|  13) |xy|  p

  7. Pumping Lemma for CFL Theorem: For every context-free language L, there is a pumping length p, such that for any string sL and |s|p, we can write s=uvxyz with1) u vi x yi z  L for every i{0,1,2,…}2) |vy|  13) |vxy|  p Note that 1) implies that uxz  L (take i=0), requirement2) says that v,y cannot be the empty strings ε and condition 3) is useful in proving non-CFL.

  8. Pumping a Parse Tree S A A u v x y z If s = uvxyz  L is long, then its parse-tree is tall.Hence, there is a path on which a variable A repeats itself. We can pump this A–A part.

  9. uvxyz L S A A u v x y z By repeating the A–A part we get…

  10. uv2xy2z L S A A A R y v u x z y x v … while removing the A–A gives…

  11. uxz  L S A u z x In general: uvixyiz  L for all i=0,1,2,…

  12. Using Pumping Lemma “Proof by contradiction. Assume that L is context free.Let p be the pumping length of L and take sL. By the pumping lemma it is possible to write s=uvxyz(with |vy|  1 and |vxy|  p) such that uvixyiz  L for all i0. However… Thus the pumping lemma does not hold for s. Contradiction. The language L is not context-free.” Here you have to be clever in picking the right s. Show that pumping up or down s gives strings that are not in L. Be careful to consider all v,x,y possibilities.

  13. Example I: Pumping anbncn Proof by contradiction; assume L = {anbncn | n0} is CF. According to the pumping lemma there is a pumping length p such that for s = apbpcp  L, we can write s = uvxyz = apbpcp,with uvixyiz  L for all i0. Two options for 1  |vxy|  p: 1) vxy = a*b*, then the string uv2xy2z has not enough letters c, hence uv2xy2zL 2) vxy = b*c*, then the string uv2xy2z has not enough letters a, hence uv2xy2zL Contradiction: the pumping lemma does not hold, hence L is not context free.

  14. Example II: (Pumping down) Prove that C = {aibjck | 0ijk } is not context-free. Let p be the pumping length, and s = apbpcp  C. Pumping lemma: s = uvxyz, such that uvixyiz  C for every i0. Two options for 1  |vxy|  p: 1) vxy = a*b*, then the string uv2xy2z has not enough letters c, hence uv2xy2zC 2) vxy = b*c*, then the string uv0xy0z = uxz has too many letters a, hence uv0xy0zC Contradiction: The pumping lemma does not hold forthis string apbpcp, hence C is not context-free.

  15. Example III: ww Prove that the language D = { ww : w{0,1}* } is not CF. You must be careful when picking the strings sD… Let p be the pumping length, take s=0p1p0p1p. Options for s=uvxyz with 1  |vxy|  p: • If vxy is to the left of the middle of 0p1p 0p1p,then second half of uv2xy2z starts with a “1”. • If vxy is to the right of the middle of 0p1p 0p1p, then first half of hence uv2xy2z ends with a “0”. • If x is in the middle of 0p1p 0p1p, then pumped down uxz equals 0p1i 0j1p  D(because i or j < p)

  16. Additional Notes on CFL • Let A1 and A2 be two context-free languages,then the union A1 A2 is also context free. • However, the intersectionA1A2 is not necessarily context free • The complementĀ1= *–A1 are not necessarily context free either

  17. Closure properties of CFLs

  18. Closure under reversal

  19. CFL not closed under intersection!

  20. Decision Problems for CFL

  21. Make a chain of everywhere a variable occurs From each production send a link to a counter counting how many variables in the prod have not yet been found to produce When a variable is found to be generating decrement Counter accordingly When counter reaches 0 the head variable is generating

  22. Undecidable problems for CFL

More Related