Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 3240: Languages and Computation Properties of Context-Free Languages.

Similar presentations


Presentation on theme: "CS 3240: Languages and Computation Properties of Context-Free Languages."— 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 Recall: Pumping Lemma for Regular Languages q1q1 qkqk qjqj 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 y i z  L for every i  {0,1,2,…} 2) |y|  1 3) |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 with 1) u v i x y i z  L for every i  {0,1,2,…} 2) |vy|  1 3) |vxy|  p Note that 1) implies that uxz  L (take i=0), requirement 2) says that v,y cannot be the empty strings ε and condition 3) is useful in proving non-CFL.

8 Pumping a Parse Tree A A uvxyz 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. S

9 uvxyz  L A A uvxyz By repeating the A–A part we get… S

10 uv 2 xy 2 z  L A u v x y z R A A v x y … while removing the A–A gives… S

11 uxz  L A uz In general: uv i xy i z  L for all i=0,1,2,… S x

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 uv i xy i z  L for all i  0. However… Thus the pumping lemma does not hold for s. Contradiction. The language L is not context-free.” Show that pumping up or down s gives strings that are not in L. Be careful to consider all v,x,y possibilities. Here you have to be clever in picking the right s.

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

14 Example II: (Pumping down) Prove that C = {a i b j c k | 0  i  j  k } is not context-free. Let p be the pumping length, and s = a p b p c p  C. Pumping lemma: s = uvxyz, such that uv i xy i z  C for every i  0. Two options for 1  |vxy|  p: 1) vxy = a*b*, then the string uv 2 xy 2 z has not enough letters c, hence uv 2 xy 2 z  C 2) vxy = b*c*, then the string uv 0 xy 0 z = uxz has too many letters a, hence uv 0 xy 0 z  C Contradiction: The pumping lemma does not hold for this string a p b p c p, 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=0 p 1 p 0 p 1 p. Options for s=uvxyz with 1  |vxy|  p: 1. If vxy is to the left of the middle of 0 p 1 p 0 p 1 p, then second half of uv 2 xy 2 z starts with a “1”. 2. If vxy is to the right of the middle of 0 p 1 p 0 p 1 p, then first half of hence uv 2 xy 2 z ends with a “0”. 3. If x is in the middle of 0 p 1 p 0 p 1 p, then pumped down uxz equals 0 p 1 i 0 j 1 p  D (because i or j < p)

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

17 Closure properties of CFLs

18 Closure under reversal

19 CFL not closed under intersection!

20

21 Decision Problems for CFL

22 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

23

24

25 Undecidable problems for CFL


Download ppt "CS 3240: Languages and Computation Properties of Context-Free Languages."

Similar presentations


Ads by Google