CI 3104 /Winter 2011: Introduction to Forml Lnguges Chpter 16: Non-Context-Free Lnguges Chpter 16: Non-Context-Free Lnguges I. Theory of utomt II. Theory of Forml Lnguges III. Theory of Turing Mchines Dr. Neji Zgui CI3104-W11 1
Chpter 16: Non-Context-Free Lnguges Theorem. Let G e context-free grmmr in Chomsky norml form. Let L e the suset of words generted y G which hve derivtions such tht ech production of the form: Nonterminl Nonterminl Nonterminl is used t most once. L is finite set of words. roof. t ech step in derivtion, nonterminl is replced y either 2 nonterminls or one terminl. Thus, if there re p productions of the form: Nonterminl Nonterminl Nonterminl word in L contins t most p+1 letters. The set of words tht contin t most p+1 letters is finite Dr. Neji Zgui CI3104-W11 2
Chpter 16: Non-Context-Free Lnguges Exmple: / Y / Y / Y Y (1) (2) (3) Y (1) (2) (3) Dr. Neji Zgui CI3104-W11 3
Chpter 16: Non-Context-Free Lnguges rnch: pth etween the root nd lef of derivtion tree Z Z Z Z Z Z the sme nonterminl twice on the sme rnch (The 2 nd is tree descendnt of the 1 st. The nonterminl is self-emedded.) C C C C two different rnches Remrk: drivtion trees re inry Dr. Neji Zgui CI3104-W11 4 C Z Z
Chpter 16: Non-Context-Free Lnguges Theorem. Let G e context-free grmmr in Chomsky norml form tht hs p productions of the form: Nonterminl Nonterminl Nonterminl. Let w e word such tht length(w) 2 p. Then in every derivtion tree for w there exists some nonterminl Z tht ppers twice on the sme rnch. Dr. Neji Zgui CI3104-W11 5
Chpter 16: Non-Context-Free Lnguges Exmple 1 st rng 2 0 nodes 2 nd rng 2 1 nodes 3 rd rng 2 2 nodes 4 th rng 2 3 nodes C Y D p=3 p+1 rows 2 p leves, mximum Y C C D Dr. Neji Zgui CI3104-W11 6
Chpter 16: Non-Context-Free Lnguges roof. tree tht hs more thn 2 p leves hs more thn p+1 rows. ( tree tht hs p+1 rows hs t most 2 p leves.) p nonterminls p+1 nonterminls 1 terminl 1 terminl Dr. Neji Zgui CI3104-W11 7
Chpter 16: Non-Context-Free Lnguges Y Y Y Y Y Y Y p=4 Y Y Y Y Y Y the rnch tht ends in hs 6 nonterminls (5 pplictions of productions contining only nonterminls) t lest one production is used more thn once Dr. Neji Zgui CI3104-W11 8
Chpter 16: Non-Context-Free Lnguges Exmple: LINDROME {Λ} /Y//// Y 2 6 = 64 1 st row 2 nd row 3 rd row 4 th row 5 th row 6 th row Dr. Neji Zgui CI3104-W11 9
Chpter 16: Non-Context-Free Lnguges Dr. Neji Zgui CI3104-W11 10
Chpter 16: Non-Context-Free Lnguges The pumping lemm (for context-free lnguges) Let G e context-free grmmr in Chomsky norml form tht hs p productions of the form: Nonterminl Nonterminl Nonterminl. Let w e word such tht length(w) 2 p. Then w cn e decomposed into 5 fctors: w = uvxyz such tht x is not t lest one of v nd y is not for ll n 1, uv n xy n z is in the lnguge generted y G. Dr. Neji Zgui CI3104-W11 11
Chpter 16: Non-Context-Free Lnguges roof. From the previous theorem, there exists non terminl tht occurs t lest twice on the sme rnch. w = uvxyz x either v, or y u Q R z v x y Dr. Neji Zgui CI3104-W11 12
Chpter 16: Non-Context-Free Lnguges Note: u, z, nd t lest one of v nd y could e. u = v = x = y = z = Dr. Neji Zgui CI3104-W11 13
Dr. Neji Zgui CI3104-W11 14 Chpter 16: Non-Context-Free Lnguges In generl: uv n xy n z R Q z u v y R Q v y x R Q z u v y R Q v y R Q v y x uvvxyyz uvvvxyyyz
Chpter 16: Non-Context-Free Lnguges lterntively: uz vy x uz uvyz uvxyz w = uvxyz x either v, or y u Q R z v x y Dr. Neji Zgui CI3104-W11 15
Chpter 16: Non-Context-Free Lnguges TRT UH UH RED O RED CCET D O n n n? O RED D Dr. Neji Zgui CI3104-W11 16