Professional Documents
Culture Documents
Outline
Context-free Languages, Context-free
grammars (CFG), Push-down Automata
(PDA)
Pumping lemma
Relations
Context free
language
regular
language
Relations
Context-free
Languages L
L = L(G)
Context-free
Grammars G
L(G) = L(M)
L = L(M)
Push-down
Automata M
Example (I)
Given the following CFG
={a, b}
SX | Y
X aXb | aX
| a
Y aYb | Yb
| b
(1) L(G) = ?
(2) Design an equivalent PDA for it.
more as than bs
SYaYbaYbbaaYbbbaabbbb
more bs than as
Observations:
Start from S, we can enter two States X
& Y, and X, Y are independent;
Ls = Lx U Ly
Lx = { aibj; i>j }
Lx = { aibj; i<j }
L(S) =
{ aibj; ij }
SX| Y
X aXb | aX
Y aYb | Yb
= { a b ; i>j } U { a b ; i<j }
i j
i j
| a
| b
Lx = { aibj; i>j }
a,/A
,/$
q0
,/
b,A/
q1
,A/
LY = { aibj; i<j }
,A/
q2
a,/A
,$/
q3
,/$
, /
Combine both
q0
,/
b,A/
b,$/$
,$/
q1 b,$/$ q2
q3
Example (II)
Given the following language:
L = {0i1j: i j 2i, i=0,1,},
= {0, 1}
(1) design a CFG for it;
(2) design a PDA for it.
= {0, 1}
red-rule
S 0S11
S
blue-rule
= {0, 1}
Need to verify L = L(G)
G=
S 0S1
S 0S11
= {0, 1}
1,X/
0,/X
,/$
,/
q0
q1
1,X/X
,$/
1,X/
q2
q3
Example (III)
Given the following language:
L = { aibjckdl: i, j, k, l=0,1,; i+k=j+l },
where the alphabet = {a, b, c, d}
NxNx
S aSd | XY
X aXb |
Y cYd |
S-->anSdn--> anXYdn
ajbj
ckdk
-->anajbjYdn
-->anajbj ckbkdn
aj
bj ck dk
= an+jbj ckbn+k
(n+j) + k = j + (n+k)
a,/X
,/$ q
1
c,$/X$
c,X/XX
,/
q2
b,$/Y$
b,Y/YY
,/
q3
c,Y/
,/
d,X/
q4
d,$/Y$
d,Y/YY
, $ / q
5
Outline
Context-free Languages, Context-free
grammars (CFG), Push-down Automata
(PDA)
Pumping Lemma
Example(4)
L1 = {0n1n0n1n | n 0}
1
2
choose
n
write z = uvwxy
z=
n n n n
0
i =1 0 1
2
0 0 ... 0 0 1 1 1 1 1 0 0 0 0 11 11
u
= uv2wx2y is NOT in
Example(5)
L2 = {0n#02n#3n | n 0 }
1
2
choose
n
write z = uvwxy
z=
n
2n
3n
0
i =#0 #0
2
0 0 ... 0 0 # 0 0 0 0 0 # 0 0 0 0 0 0 0 0
u
= uv2wx2y is NOT in
L2
1. Neither v nor x can contain #
2. 1:2:3 ratio cant be maintained since at least
one segment NOT in v and x