Beruflich Dokumente
Kultur Dokumente
tape
tape head
stack head
finite
control
stack
a, v/u
,f=
for f
F)
p | (p,u) (q, a, v) }.
1, 0/
Solution 2.
Consider a CFG
G = ({S}, {0,1}, {S | 0S1}, S).
, S/1
, /S
, /0
, S/
0, 0/
1, 1/
, /S
A x1 x2 xn in R
, /x1
a, a/ for a in
Theorem
A language L is CFL it can be accepted by a PDA.
Example 2
Idea
To check if #b ( x) # a ( x) 2#b ( x), we need to cancel a with b.
For each b, we need to cancel sometimes one a and sometimes
two a. Do we need to make a deterministic choice at each
cancellation? No, the concept of nondeterministic computation
solves this trouble : As long as a correct choice exists, the input
string x would be accepted!
(p, s) (s, , )
, / s
(q, s) (p, a, s)
(p, a) (q, , )
a, s / s
, / a
a
s
(q1, a) (p, a, a)
(p, a) (q1, , )
a, a / a
, / a
a
a
(p, ) (p, a, b)
a,b /
(p, b) (p, a, b)
a, b / b'
(p, ) (p, a, b)
a,b' /
(r1, s) (p, b, s)
(p, b) (r1, , )
b, s / s
, / b
b
s
(r2, b) (p, b, b)
(p, b) (r2, , )
b, b / b
, / b
b
b
(r3, b) (p, b, b)
(p, b) (r3, , )
b, b' / b'
, / b
b
b
(p, ) (p, b, a)
b, a /
a
a
(t, ) (p, b, a)
b, a /
,a /
(p, ) (t, , a)
a
z
b
z
za
,b' /
, z / z
za
(p, ) (p, , s)
,s /
a,b /
a, b / b'
, / s
a,b' /
a, z / z
z b,b'
, / a
b, a /
b, a /
, z / z
za
b, z / z
za
,a /
, / b
, / b'
,s /
Example 3
Construct PDA accepting {x {a, b} | #b ( x) # a ( x) 2#b ( x)}.
Idea
To have #b ( x) # a ( x), we must have a b which cancel two a ' s.
Let the first b do the job.
a,b /
Solution
a, b / b'
a,b' /
a, z / z
, / s
a, b / b'
11
z b,b'
b, a /
,a /
, / b'
, / a
, z / z
za
b, a /
b, a /
b, z / z
, z / z
za
, / a
,s /
za
,a /
, / b
, / b'
a, z / z
z b,b'
b, z / z
za
, / b
Example 4
Construct PDA accepting {x {a, b} | #b ( x) # a ( x) 2#b ( x)}.
Idea
To have # a ( x) 2#b ( x), we must have a b which cancel one a.
Let the first b do the job.
Solution
, / s
a,b /
a, b / b'
a,b' /
a, z / z
a,b /
11
z b,b'
b, a /
, / a
, / a
,s /
b, a /
b, a /
, z / z
za
a, z / z
z b,b'
b, z / z
za
,a /
, / b
, / b'
b, z / z
za
, / b