2/28/2006
CSE 2001, Winter 2006
1
CSE 2001:
Introduction to Theory of Computation
Winter 2006
Suprakash Datta
[email protected]
Office: CSEB 3043
Phone: 4167362100 ext 77875
Course page: http://www.cs.yorku.ca/course/2001
Some of these slides are adapted from Wim van Dam’s slides
(
www.cs.berkeley.edu/~vandam/CS172/
)
2/28/2006
CSE 2001, Winter 2006
2
Next
•
Equivalence of PDA’s, CFL’s
•
NonCF languages
•
CFL pumping lemma
•
Closure properties of CFLs
2/28/2006
CSE 2001, Winter 2006
3
PDAs and CFL
Theorem 2.12
:
A language L is contextfree
if and only of there is a pushdown automata M
that recognizes L.
Two step proof
:
1) Given a CFG G, construct a PDA M
G
2) Given a PDA M, make a CFG G
M
2/28/2006
CSE 2001, Winter 2006
4
Converting a CFL to a PDA
Basic idea
•
Start with the start symbol
•
Nondeterministically apply rules
•
Stop when a string of terminals is left.
•
Compare with input – accept if match.
Detail:
•
How do you store the intermediate
string on the stack?
2/28/2006
CSE 2001, Winter 2006
5
Converting a CFL to a PDA  2
•
In q
start
, initialize the stack to contain S$
and make an
ε
transition to q
loop
.
•
In q
loop
, if top of stack contains a variable
A, replace it with a terminal w for some
rule A
→
w
•
Else, if top of stack contains a terminal w,
compare with next input symbol. If
unequal, reject.
•
Else if the top of the stack is $ (empty
stack), make an
ε
transition to q
accept
.
2/28/2006
CSE 2001, Winter 2006
6
Converting a PDA to a CFG
Basic idea:
•
For each pair of states p,q use a
variable A
pq
which generates all strings
that take the PDA from p to q.
•
The start variable is A
q
0
q
accept
•
Details: Assume that the PDA
– Has a single accept state
– Empties stack before accepting
– Each transition either pops or pushes.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
2/28/2006
CSE 2001, Winter 2006
7
Converting a PDA to a CFG  2
•
∀
p,q,r,s
∈
Q, t
∈ Γ
, a,b
∈ Σ
ε
, if
δ
(p,a,
ε
)
contains (r,t) and if
δ
(s,b,t) contains (q,
ε
)
add the rule A
pq
→
aA
rs
b
•
∀
p,q,r
∈
Q, add the rule A
pq
→
A
pr
A
rq
•
∀
p
∈
Q, add the rule A
pp
→
ε
2/28/2006
CSE 2001, Winter 2006
8
Converting a PDA to a CFG  3
Correctness  Easier direction: If A
pq
generates x, then x brings PDA P from p
with empty stack to q with empty stack.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Winter '10
 n
 Formal languages, Contextfree grammar, CFL, contextfree language

Click to edit the document details