You are on page 1of 12

Languages that are and are not context free

CENG 280

Languages that are and are not context free CENG 280 1 / 12
Course outline

Preliminaries: Alphabets and languages


Regular languages PL
Context-free languages
Context-free grammars
Parse trees
Push-down automaton
Push-down automaton - context-free languages
Languages that are and that are not context-free, Pumping lemma
Turing-machines

Languages that are and are not context free CENG 280 2 / 12
Pumping theorem for CFL

Given a context free grammar G = (V , ⌃, R, S).

I
The fanout of G , denoted by (G ) is the largest number of symbols
on the right hand side of any rule in R.
A path in a parse tree is a sequence of distinct nodes connected with
line segments, where the first one is the root and the last one is a leaf.
The length of a path is the number of line segments in it.
The height of a parse tree is the length of the longest path in it.

Languages that are and are not context free CENG 280 3 / 12
Pumping theorem for CFL
Example
Consider G = (V , ⌃, R, S) with Iv 2 1 2 007 3
R : S ! aSa, S ! bTb, T ! bTb, T ! e. ST
I F I
s bTb bb T s

ie
sass.a eab ban n9obbmIabbb7n7Eepos h
ftp.qs

Sta z distinct nonterminals


b Hb
S abbbba

b b Et b ba
g
Languages that are and are not context free
n

CENG 280 4 / 12
Pumping theorem for CFL
Lemma
The yield of a parse tree of G of height h has length at most (G )h .
induction A
h 0
Base case L t.u.z.hu
true for parse trees of length
III Suppose that the result is
up to h I
Show that is true for porse trees with length htt
S ns.oc
joins 0CG
h
0cal E
4
e

Languages that are and are not context free CENG 280 5 / 12
Pumping theorem for CFL

Corollary
The parse tree of any w 2 L(G ) with |w | > (G )h must have a path
longer than h.

Theorem
Let G = (V , ⌃, R, S) be a context-free grammar. Then any string
w 2 L(G ) of length greater than (G )|V \⌃| can be written as w = uvxyz
in such a way that

Ei I
v or y is non empty (i.e. |vy | > 0) and
uv n xy n z 2 L(G ) for every n 0.

Languages that are and are not context free CENG 280 6 / 12
Proof of pumping theorem for CFL
T S M Il
Iwl Ca
e
pumping length

a
ha II's a path with h non termina

should be a non termina


Buy PHP there

w
V X y repealed along a path
A 5 X S uA.z ur
Aya 3 ux yz
A VIL s uAz uvAyz uvv yyz uv4y
S uAz UX 2

Ivy 1 0 uv3xy3z Uvnxynz


p T is the parse tree
of Eu with smallest of leaves

l o
Ivy Languages that are and are not context free CENG 280 7 / 12
Pumping theorem for CFL - Examples
L is not CF
Example By Pumping theorer
N E
Show that L = {an b n c n | n 0} is not context-free. 0cg
_n
Assume that L is CF then there exists G LCG L
Let LEE pumping length
a ab be C
w Iwl 2K WE L
Kbk.ck xxy_vxywe
Iwl 314 my
theorem there exists a split w XyZ
Then by Pumping Uyl O
SG
Uvnxynz EL for any n O
i.eases
FI iEohEIbckEczm
III of ab or b's is strictly 55in
f
3 D uv2 y2z
Vxy a greater then the o's
Wy bib Ivy1 420
violated
property is

qrTory
yaenhaifseqlleffff.ge's
VXy
D VEY
b'Eggs

EE
uv2xy2zE contains 2
symbols ai.ba oib
Vydoes.net 4
a 1 170
Ivy
Languages that are and are not context free CENG 280 8 / 12
Pumping theorem for CFL - Examples
Example
Show that L = {w 2 {a, b, c}? | w has equal number of a0 s, b 0 s and c 0 s}
is not context-free.
2 canbench In 03 L is not context free
2 a b c L is regular

2 h L L
not context free
regular
if I was contextfree 2 NL context fee
I
L is not context free

Languages that are and are not context free CENG 280 9 / 12
Pumping theorem for CFL
Theorem
The context-free languages are not closed under intersection or
complementation.

Proof? L Le context free L z IU


L h L is not contextfree
anbhan
Li a om l n m Tog
b s AC
2e
EIEAcbfeeY4L.hLz
oibm mln.ms.org

303 Lanbncn In

Languages that are and are not context free CENG 280 10 / 12
Pumping theorem for CFL

Theorem (Strong version)


Let G = (V , ⌃, R, S) be a context-free grammar. Then there exists k, K
such that any string w 2 L(G ) with |w | > K can be written as w = uvxyz
in such a way that |vy | > 0, |vxy |  k and uv n xy n z 2 L(G ) for every
I
n 0.
14 0 CG one
I two non terminated

Latkes ai
th

Languages that are and are not context free CENG 280 11 / 12
Pumping theorem for CFL
Example
2
Show that L = {an | n 0} is not context free.

Assume that L is context free Then


by strong PT
there exists K K
e
susch that Iwl K there
exist split w
uvxyzlvxylkkuvnxynz.GL

w Ork 1wl K K
K
w Uv
Xyz uv2 y2z L
12 21 LK K2 L K2tmL K 1112
MLK I
124211 1
Ivy so PT 2 is not contextfree
by
Languages that are and are not context free CENG 280 12 / 12

You might also like