Definiton: Derivation tree Let G = ( V, T, S, P ) be a cfg. An ordered tree is called a derivation tree for G if • the root is labelled S • every interior vertex has a label from V • Every leaf has a label from T ∪ { λ } • If a vertex has a label A and its children are labelled X 1 , X 2 , X 3 , . . . X n from left to right, then A → X 1 X 2 . . . X n is a production in P . • A leaf labelled λ has no siblings. 1
Chomsky Normal Form (CNF) A cfg G is in CNF if all productions are of the form A → BC or A → a where A, B, C ∈ V and a ∈ T . 2
Given a cfg G , to put it into CNF, we perform the following steps: 1. Remove all λ -productions. 2. Remove all unit productions. 3. Remove all useless productions. 4. Remove productions not of the form A → BC or A → a . 3
Griebach Normal Form A cfg G is in GNF if all productions are of the form A → ax where a ∈ T and x ∈ V ∗ 4
HW Q2 (revised): Let G be a context-free grammar in CNF, and let w ∈ L ( G ) be the yield of a parse tree for w according to the grammar G . Prove using induction that if the length of the longest path in the tree is n , then | w | ≤ 2 n − 1 . 5
Pumping Lemma for CFLs Let L be a CFL. Then ∃ m > 0 such that ∀ w ∈ L with | w | ≥ m ∃ a way to break up w such that w = uvxyz with | vxy | ≤ m and | vy | ≥ 1 ∀ i ≥ 0 uv i xy i z ∈ L 6
To use the pumping lemma to show that a given L is not context- free, we play an adversary game as follows: 1. Assume adversary picks m , the constant of the pumping lemma/ 2. We get to pick w , a string in L that is longer than m . 3. Adversary gets to break up w into uvxyz , while obeying the rules that | vxy | ≤ m and | vy | ≥ 1. 4. We get to pick i (the number of times to pump v and y . We win if we show that uv i xy i z / ∈ L . 7
Closure properties Operation Regular CFLs DCFLs Union Yes Yes No Concatenation Yes Yes No Kleene closure Yes Yes No Intersection Yes No No Int. with regular language Yes Yes Yes Complementation Yes No Yes Reversal Yes Yes No 8
Decision algorithms Given a cfg G , there are algorithms to determine the following questions: 1. Is L ( G ) empty? 2. Is L ( G ) finite? 3. Given a string x , is x ∈ L ( G )? 9
Decision algorithms But for many questions about CFLs that no algorithm can an- swer (we will formalize what we mean by this later). Here are some examples: Let G be a cfg. 1. Is L ( G ) = Σ ∗ ? 2. Is L ( G ) a regular set? 3. Is L ( G ) a DCFL? 4. Is L ( G ) inherently ambiguous? 5. Is the complement of L ( G ) a cfl? 10
Let G 1 , G 2 be cfgs and let R be a regular set. 6. Is L ( G 1 ) = L ( G 2 )? 7. Is L ( G 1 ) ∩ L ( G 2 ) = ∅ ? 8. Is L ( G 1 ) ∩ L ( G 2 ) a cfl? 9. Is L ( G 1 ) ⊆ L ( G 2 )? 10. Is L ( G ) = R ?
Recommend
More recommend