Download presentation
Presentation is loading. Please wait.
1
Chapter 2 Context-Free Language - 02
Original author : Prof. Y-p Chen Reproduced : ccming 2010/10/20
2
2.3 Non-Context-Free Language
2.3.1 Pumping Lemma for CFLs Theorem 2.34 – Pumping lemma for context-free languages: If A is a context-free language, then there is a number p (the pumping length) where, if s is any string in A of length at least p, then s may be divided into five pieces, s = uvxyz satisfying the conditions
3
Proof idea : When the string is long enough, some variable(s) must be repeatedly used in derivations. Proof : Let G be a CFG for CFL A. Let b be the maximum number if symbols in the right-hand side of a rule. From the start variable, there are at most b leaves for one step; at most b2 leaves for 2 steps; at most bh leaves for h steps. Conversely if a generated string is at least bh+1 long, each of its parse tree must be at least h+1 high. Say |V| is the number of variables in G. We set p, the pumping length, to be b|V|+1. Now if s is a string in A and its length is p or more, its parse tree must be at least |V|+1 high.
4
For any such string s, let τ be the parse tree with the smallest number of nodes. We know that τ must be at least |V|+1 high, so it must contain a path from the root to a leaf of length at least |V|+1. That path has least |V|+2 nodes; one at a terminal, the others at variables. Hence that path has at least |V|+1 variables. With G having only |V| variables, some variable R appears more than once on that. So we have :
6
How to use the pumping lemma for CFLs:
Condition 2: Both v and y are not ε . τ is the parse tree with the smallest number of nodes. Condition 3: vxy has length at most p. Choose R so that both occurrence fall within the bottom |V|+1 variables on the path. How to use the pumping lemma for CFLs: Assume the language, say B, is context free in order to obtain a contradiction. By the pumping lemma for CLFs, a pumping length p exist, and any string w∈B can be pumped if |w|≧p Find a string s ∈ B , |s|≧p that s cannot be pumped as described in the pumping lemma The contradiction is obtained, so that B is not context-free
7
Example 2.36 :
8
2.3.2 Ogden’s lemma for CFLs
9
Example :
11
2.3.3 Ogden’s lemma for CFGs
12
2.3.4 Inherently Ambiguous CFLs
Theorem : There exists an inherently ambiguous CFL Proof : One of such language is
16
2.4 Properties of CLFs 2.4.1 substitutions
18
2.4.2 Closure Properties Let A and B be context-free languages. Let R be a regular language. The result of the following operations are all context-free languages:
19
2.4.2 Membership Test : CYK Algorithm
20
Example : w = baaba
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.