Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pumping Lemma for CFLs. Theorem 7.17: Let G be a CFG in CNF and w a string in L(G). Suppose we have a parse tree for w. If the length of the longest path.

Similar presentations


Presentation on theme: "Pumping Lemma for CFLs. Theorem 7.17: Let G be a CFG in CNF and w a string in L(G). Suppose we have a parse tree for w. If the length of the longest path."— Presentation transcript:

1 Pumping Lemma for CFLs

2 Theorem 7.17: Let G be a CFG in CNF and w a string in L(G). Suppose we have a parse tree for w. If the length of the longest path of the parse tree is n, then |w| ≤ 2 n-1 Proof: induction on n.

3 Theorem 7.18: (Pumping Lemma for Context- free Languages) Let L be a CFL. Then there exists a constant n such that if z is any string in L such that |z|  n, then we can write z = uvwxy, satisfying the following conditions: 1) |vwx|  n 2) vx   3) for all i  0, uv i wx i y is in L.

4 Applications of pumping lemma: {a n b n c n | n > 0} {a n b m c n d m | m,n >0} {ww | w is in {0, 1} * }

5 Closure Properties of CFLs

6 Definition (substitution): Let  be a class of languages and let L   * be in . Suppose that for each a in , L a is a language in .  is closed under substitution if for all choices of L, L' = {x 1 x 2 …x n | a 1 a 2 …a n is in L x 1 is in L x 2 is in L … x n is in L } is in . a1a1 a2a2 anan

7 Theorem 7.23: The class of context-free languages is closed under substitution Proof: Let G = (V, T, P, S) be such that L(G) = L and G a = (V a, T a, P a, S a ) be such that L a = L(G a ). Let L 1 be the language resulting from the substitution of L a ’s for a’s in L. Construct G 1 = (V 1, T 1, P 1, S) where V 1 is the union of V and all V a ’s T 1 is the union of T and all T a ’s P 1 is the union of all P a ’s and the productions of P with S a substituted for a Then, L 1 = L(G 1 )

8 Corollary (Theorem 7.24): The context-free languages are closed under: 1)Union 2)Concatenation 3)*, + 4)Homomorphism Theorem 7.25: If L is a CFL, then L R is also a CFL

9 Theorem: The class of context-free languages is not closed under intersection. Theorem 7.27: The class of context-free languages are closed under intersection with regular languages Theorem 7.29: The following are true about CFLs L, L 1, and L 2, and a regular language R. 1.L-R is a CFL 2.Complement of L is not necessarily a CFL 3.L 1 – L 2 is not necessarily a CFL

10 Theorem: If L is a CFL and h is a homomorphism, then h -1 (L) is a CFL. Examples: L = {a m b n a m b n | m, n ≥ 1} is not a CFL L = {ww | w in {a, b} * } is not a CFL L = {begin integer w; w := 1; end | w is a string in {a, b} + } is not a CFL

11 Definition: A language which is defined by a DPDA is called a deterministic context-free language. (The class of grammars called LR(k) grammars generate deterministic CFLs. Every deterministic CFL has a LR(1) grammar)

12 Lemma: If L is a deterministic CFL, then h -1 (L) is a deterministic CFL

13 Theorem: The class of deterministic CFL’s is closed under complement and are not closed under union, intersection, homomorphism, concatenation, or (* or +). The deterministic CFL’s is a proper subset of the class of CFL’s.


Download ppt "Pumping Lemma for CFLs. Theorem 7.17: Let G be a CFG in CNF and w a string in L(G). Suppose we have a parse tree for w. If the length of the longest path."

Similar presentations


Ads by Google