Title: Equivalence of Pushdown Automata and Context-Free Grammars (1)
1Equivalence of Pushdown Automata and Context-Free
Grammars (1)
Theorem. Given a context-free grammar CG
(?,NT,R,S) , then there is a pushdown automaton
PA (Q,?,?,?,s,F) such that L(CG) L(PA)
Construction Q s,f, F f, ? ?, ? ?
? NT
- Make a rule pushing S in the stack
- ((s,e,e),(f,S))
- For each rule C ? w in R
- ((f,e,C),(f,w))
- For each terminal ? in ?
- ((f, ?, ?),(f,e))
2Sketch of the Proof
(taking the leftmost non terminal in T1)
(f, e,e)
3Equivalence of Pushdown Automata and Context-Free
Grammars (2)
Theorem. Given a pushdown automata PA
(Q,?,?,?,s,F) then, there exists a context-free
grammar CG (?,NT,R,S) such that L(PA) L(CG)
Steps 1. Obtain an equivalent pushdown automata
accepting by empty stack 2. Obtain an equivalent
simple pushdown automata (Q,?,?, ,?,s) 3. Use
(Q,?,?, ,?,s) to obtain a context-free
grammar CG (?,NT,R,S) such that L(SAE) L(CG)
4Simple Pushdown Automata
A pushdown automata SA is simple if for each ((q,
?,?), (q,?)) in ? then ? ? ? and SA accepts by
empty stack
(that means no pop of empty word or more than one
character)
Theorem. Given a pushdown automata accepting a
language by empty stack PAE (Q,?,?,?,s) there
is a simple pushdown automata SPA (Q,?,?,
,?,s) accepting by empty stack such that
L(SAE) L(PAE)
5Proof
Idea always maintain on top of the stack
- Replace each transformation ((q, ?,e), (q,?))
with a transformation ((q, ?, ), (q, ?))
- Replace each transition ((q, ?,w), (q,?)), where
w is a word with at least 2 characters, w ?1 ?2
?n - with
((q,e, ?1),(q1,e)) ((q1,e, ?2),(q2,e))
((qn-1,e, ?n),(q, ?)) where q1,.., qn-1 are new
states
6Last step From a Simple Pushdown Automaton to a
Context-Free Grammar
Suppose that we have the transition
((s,a,A),(q,B1B2Bn))
First attempt add the rule A ? a B1B2Bn
Problem with first attempt 1.
Doesnt consider the states s or q
2. Doesnt consider the state where it is going
to end after popping B1B2Bn
- Solution Nonterminals will have the form
s,A,p, - Where s and p are in Q and A is in ?
- Roughly, s,A,p indicates that we can reach
state p from state s after popping A from the
stack
7Special Case
- If ((s,a,A),(q,e)) is in ? then add the rule
- s,A,q ? a
8General Case
If Nonterminals are having the form s,A,p and
we have the transition
((s,a,A),(q,B1B2Bn))
Our rule has the form s,A,? ? aq, B1,?
?, B2,? ?, Bn,? With which states should we
fill the question marks?
Problem we dont know the states p2, ,
pn-1, p
9General Case (2)
Solution take all possible p2, , pn-1, p
10Resulting Context-Free Grammar
Grammar
- For every p ? Q we add the rule
- S ? s, , p
- If ((s,a,A),(q,e)) is in ? then add the rule
- s,A,q ? a
- If ((s,a,A),(q,B1B2Bn)) is in ? then we add the
rules - s,A,p ? aq, B1, p2 p2, B2, p3 pn-1,
Bn, p - one for each possible combination p2, ,
pn-1, p
11Homework for Friday
- Consider the grammar from Example 3.1.5 of the
book (Page 74) - Use the grammar to generate the word (v
(v/(vv))) - Convert it into a pushdown automaton.
- Show that the word (v (v/(vv))) is accepted by
the pushdown automaton - Consider the pushdown automaton from Example
3.3.1 of the book (Page 83) - What is the language accepted by this pushdown
automaton - Convert it into an equivalent pushdown automaton
accepting by empty stack - Consider the following pushdown automaton P
accepting by empty stack - What is the language accepted by it?
- Convert P to a simple pushdown automaton. Note
you will need to figure out yourself how to make
the transformation. The procedure in the book and
the one in the slides has some errors. Assume
that the initial configuration is
((s,a,e),(s,a)) ((s,e,e),(f,e)) ((f,b,aa),(f,e))