Properties of Context-Free Languages Wen-Guey Tzeng Computer Science Department National Chiao Tung University
Pumping Lemma for CFL • Let L be a CFL. – There is a constant integer m. – For any w L, |w| m, we can decompose w into u, v, x, y, z with • w=uvxyz • |vxy| m • |vy| 1 – such that uv i xy i z L for all i=0, 1, 2, … 2017 Spring 2
Example: G=({S, A, B, C,}, T, S, P) in CNF, w=bbaabbab • For every path longer than S 5 = |V|+1, there are repetitive internal nodes. C A • S-A-B-A-C-a A S B C b a B B A B b b B C B C b a b a 2017 Spring 3
Abstract: • S uAz uvAyz uvxyz=w • S uAz uvAyz uvvAyyz … uv i Ay i z uv i xy i z for any i 0 • For w to have a high derivation tree with h >= |V|+1, |w| >= 2 |V| =m 2017 Spring 4
Example • Show that L={ : {a, b}*} is not context-free. 2017 Spring 5
2017 Spring 6
Example • Show that L={a n b n c n : n 0} is not context-free. 2017 Spring 7
Example • Show that L={a n b j : n=j 2 } is not context-free. 2017 Spring 8
2017 Spring 9
Closure Properties • The family of CFL’s are closed under – Union – Concatenation – star closure. • Assume that L 1 and L 2 are two CFL’s with CFG G 1 ={V 1 , T, S 1 , P 1 } and G 1 ={V 2 , T, S 2 , P 2 }. Assume that V 1 V 2 = . – Construct G 3 for L 3 =L 1 L 2 – Construct G 4 for L 4 =L 1 L 2 – Construct G 5 for L 5 =L 1 * 2017 Spring 10
• G 3 • G 4 • G 5 2017 Spring 11
Non-closed operations • The family of CFL’s are NOT closed under – intersection – complementation • Why? 2017 Spring 12
• Not closed under intersection – Why? – Example, • L 1 ={a n b n c m : n, m 0}, L 2 ={a n b m c m : n, m 0} are both context-free • But, L 3 =L 1 L 2 ={a n b n c n : n 0} is not context-free 2017 Spring 13
• Not closed under complementation. – Otherwise, L 3 = L 1 L 2 = comp(comp(L 1 ) comp(L 2 )) is context-free. – Example • L 2 =Comp(L 1 ) is context-free, where L 1 ={a n b n c n : n 0} • But, Comp(L 2 ) = L 1 is not context-free 2017 Spring 14
Closed: regular intersection • If L 1 is context-free and L 2 is regular, then L 1 L 2 is context-free. • Why? 2017 Spring 15
• Example – Show that L={w {a, b, c}* : n a (w)=n b (w)=n c (w)} is not context free. – Consider regular language L 2 =L(a*b*c*). – L 3 = L L 2 = {a n b n c n : n 0} is not context-free – Thus, L is not context-free. 2017 Spring 16
Recommend
More recommend