1 / 20

CSCI 3130: Formal languages and automata theory

Fall 2011. The Chinese University of Hong Kong. CSCI 3130: Formal languages and automata theory. Limitations of pushdown automata. Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130. Non context-free languages. ✔. L 1 = { a n b n : n ≥ 0}

hector
Télécharger la présentation

CSCI 3130: Formal languages and automata theory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fall 2011 The Chinese University of Hong Kong CSCI 3130: Formal languages and automata theory Limitations of pushdown automata Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130

  2. Non context-free languages ✔ L1 = {anbn: n ≥ 0} L2 = {s: s has same number of as and bs} L3 = {anbncn: n ≥ 0} L4 = {ssR: s {a, b}*} L5 = {ss: s {a, b}*} ✔ ? These are not regular Are they context-free?

  3. An attempt • Let’s try to design a CFG or PDA L3 = {anbncn: n ≥ 0} read a / push x S → aBc | e B → ?? read b / pop x ???

  4. What would happen if... • Suppose we could construct some CFG for L3, e.g. • Let’s do some long derivations • S  BC  CSC  aSC  aBCC  abCC  abaC  abaSB •  abaBCB  ababCB  ababaB •  ababab S  BC B  CS | b C  SB | a . . .

  5. Repetition in long derivations • If derivation is long enough, some variable mustappear twice on same path in parse tree S • S  BC  CSC  aSC  aBCC  abCC  abaC  abaSB •  abaBCB  ababCB  ababaB •  ababab B C C S S B B C B C b b b a a a

  6. Pumping example • Then we can “cut and paste” part of parse tree S S ababbabb ababab ✗ C B B C C S B S a b C C B B C S S B b b a S B B C B C b B C a b a b a b a b

  7. Pumping example • We can repeat this many times • Every sufficiently large derivation will have a middle part that can be repeated indefinitely ababbabb ababbbabbb ababab ✗ ✗ ababnabnbb

  8. Pumping in general u u u u y y y y A A A A w v v v x x x A A A w v v x x A A w v x A w uv2wx2y uvwxy uv3wx3y uwy

  9. Example L3 = {anbncn: n ≥ 0} • If L3 has a context-free grammar G, then • What happens for anbncn? • No matter how it is split, uv2wx2y∉L3! If uvwxy is in G, so are uv2wx2y, uv3wx3y, uwy, ... aaa ... aabbb ... bbccc ... cc x v w y u

  10. Pumping lemma for context-free languages • Pumping lemma: For every context-free language L There exists a number nsuch that for every string z in L, we can write z = uvwxy where |vwx| ≤ n |vx| ≥ 1 For every i≥ 0, the string uviwxiy is in L. x v w y u

  11. Pumping lemma for context-free languages • So to prove L is not context-free, it is enough that For every nthere exists z in L, such that forevery way of writing z = uvwxy where |vwx| ≤ n and  |vx| ≥ 1, the string uviwxiy isnot in L for some i≥ 0. x v w y u

  12. Proving language is not context-free • Like for regular languages, you need a strategy that always wins you this game Donald choose nwrite z = uvwxy(|vwx| ≤ n,|vx| ≥ 1) you choose zLchoose iyou win if uviwxiyL 1 2 At least oneis not empty x v w y u ≤ n

  13. Example Donald choose nwrite z = uvwxy(|vwx| ≤ n,|vx| ≥ 1) you choose zLchoose iyou win if uviwxiyL 1 2 L3 = {anbncn: n ≥ 0} choose n z= anbncn 1 write z = uvwxy i = ? 2 aaa ... aabbb ... bbccc ... cc x v w y u

  14. Example • Case 1:v or x contains two kinds of symbolsThen uv2wx2y not in L3 because pattern is wrong • Case 2: v and x both contain one kind of symbolThen uv2wx2y does not have same number of as, bs, cs aaa ... aabbb ... bbccc ... cc v x aaa ... aabbb ... bbccc ... cc v x

  15. More examples ✔ L1 = {anbn: n ≥ 0} L2 = {s: s has same number of as and bs} L3 = {anbncn: n ≥ 0} L4 = {ssR: s∈ {a, b}*} L5 = {ss: s∈ {a, b}*} ✔ ✘ ✔ Which is context-free?

  16. Example L5 = {ss: s∈ {a, b}*} choose n z= anbanb 1 write z = uvwxy i = ? 2 a a a a a a a a a b a a a a a a a a a b What if: a a a a a a a a a b a a a a a a a a a b x v w y u x v w y u

  17. Example L5 = {ss: s {a, b}*} choose n z= anbnanbn 1 write z = uvwxy i = ? 2 Recall that |vwx| ≤ n a a a a a a b b b b b b a a a a a a b b b b b b x v w y u

  18. Example Three cases a a a a a a b b b b b b a a a a a a b b b b b b Case 1: x v w vwx is in the first half of anbnanbn a a a a a a b b b b b b a a a a a a b b b b b b Case 2: x v w vwx is in the middle part of anbnanbn a a a a a a b b b b b b a a a a a a b b b b b b Case 3: x v w vwx is in the second half of anbnanbn

  19. Example Apply pumping with i = 0 a a a a a a b b b b b b a a a a a a b b b b b b Case 1: x v w uwy looks like ajbkanbn, where j < n or k < n a a a a a a b b b b b b a a a a a a b b b b b b Case 2: x v w uwy looks like anbjakbn, where j < n or k < n a a a a a a b b b b b b a a a a a a b b b b b b Case 3: x v w uwy looks like anbnajbk, where j < n or k < n

  20. Example Apply pumping with i = 0 L5 = {ss: s∈ {a, b}*} Case 1: uv0wx0y looks like ajbkanbn, where j < n or k < n Not of the form ss Case 2: uv0wx0y looks like anbjakbn, where j < n or k < n Not of the form ss uv0wx0y looks like anbnajbk, where j < n or k < n Case 3: Not of the form ss This covers all the cases, so L5 is not context-free

More Related