Вы находитесь на странице: 1из 32

2.

2 Pushdown Automata

Theory of Computation
CCPS3603
Prof. Ts Dr. Zainab Abu Bakar FASc
Acknowledgement
Michael Sipser (2013). Introduction to the
Theory of Computation. Thomson, 3th
edition
Topics
2.0 Context-Free Languages
2.1 Context-Free Grammars
2.2 Pushdown Automata
2.3 Non-Context-Free Languages
2.2 Pushdown Automata
• A new type of computational model called
pushdown automata.
• These automata are like nondeterministic
finite automata but have an extra
component called a stack.
• The stack provides additional memory
beyond the finite amount available in the
control.
• The stack allows pushdown automata to
recognize some nonregular languages.
4
2.2 Pushdown Automata
• A schematic representation of a finite automaton.
• The control represents the states and transition
function, the tape contains the input string, and the
arrow represents the input head, pointing at the next
input symbol to be read.
2.2 Pushdown Automata
• With the addition of a stack component we obtain a
schematic representation of a pushdown automaton,
as shown in the Figure 2.12
2.2 Pushdown Automata
• A pushdown automaton (PDA) can write symbols on the stack
and read them back later.
• Writing a symbol “pushes down” all the other symbols on the
stack.
• At any time the symbol on the top of the stack can be read and
removed.
• The remaining symbols then move back up.
• Writing a symbol on the stack is often referred to as pushing,
and removing a symbol is referred to as popping it.
– May be done only at the top.
– “last in, first out” storage device.
• Example is having plates on a cafeteria serving counter.
– The stack of plates rests on a spring so that when a new plate is placed
on top of the stack, the plates below it move down.
2.2 Pushdown Automata
• Recall that a finite automaton is unable to
recognize the language {0n1n|n ≥ 0} because it
cannot store very large numbers in its finite
memory
• As each 0 is read, it is pushed onto the stack.
• As each 1 is read, a 0 is popped from the stack.
– If the stack becomes empty exactly when the last 1
is read – accept.
– Otherwise – reject.
2.2.1 Formal Definition of a
Pushdown Automaton
2.2.1 Formal Definition of a
Pushdown Automaton
• A pushdown automaton M = (Q,Σ, Γ, δ,
q0, F) computes as follows.
• It accepts
– input w if w can be written as w = w1w2 · ·
·wm, where each wi ∈ Σε and
– sequences of states r0, r1, . . . , rm ∈ Q and
– strings s0, s1, . . . , sm ∈ Γ* represent the
sequence of stack
2.2.1 Formal Definition of a
Pushdown Automaton
Satisfy the following three conditions.
1. r0 = q0 and s0 = ε. The start state and with
an empty stack.
2. For i = 0, . . .,m − 1, we have (ri+1, b) ∈ δ(ri,
wi+1, a), where si = at and si+1 = bt for some
a, b ∈ Γε and t ∈ Γ*. M moves properly
according to the state, stack, and next
input symbol.
3. rm ∈ F. An accept state occurs at the input
end
Example 2.14
• PDA recognizes the language {0n1n| n ≥ 0}. Let M1 be
(Q,Σ, Γ, δ, q1, F), where
Q = {q1, q2, q3, q4},
Σ = {0,1},
Γ = {0, $},
F = {q1, q4}, and
δ is given by the following table, wherein blank entries
signify ∅.
Example 2.14
• This PDA is able to get the same effect by initially
placing a special symbol $ on the stack.
• Then if it ever sees the $ again, it knows that the
stack effectively is empty.
Example 2.16
• Pushdown automaton that recognizes the
language {aibjck|i,j,k ≥0 and i = j or i = k}
• Bit tricky because the machine doesn’t know
in advance whether to match the a’s with the
b’s or the c’s – use nondeterminism
• Think of the machine as having two branches
of its nondeterminism, one for each possible
guess
Example 2.16
Example 2.18
• PDA M3 recognizing the language{wwR|w ∈{ 0,1}*}
• Recall that wR means w written backwards
• Begin by pushing the symbols that are read onto the
stack
• At each point, nondeterministically guess that the
middle of the string has been reached and then
change into popping off the stack for each symbol
read, checking to see that they are the same.
• If they were always the same symbol and the stack
empties at the same time as the input is finished,
accept; otherwise reject
Example 2.18
2.2.2 Equivalence with Context-free
Grammars
• Context-free grammars and pushdown
automata are equivalent in power
• Both are capable of describing the class
of context-free languages
• Note that a context-free language to be
any language that can be described with
a context-free grammar
CFLG-s and PDA-s are Equivalent
Theorem:
A language is CFL if and only if there exists
a PDA accepting it.
Lemma->
For any CFL L, there exists a PDA P such
that L = L(P).
19
Proof Idea
• Since L is a CFL there exists a CFG G such
that L=L(G). We will present a PDA P, that
recognizes L.
• The PDA P starts with a word w ∈ Σ*
on its input.
• In order to decide whether w ∈ L(G), P
simulates the derivation of w.

20
Proof Idea (cont.)
• Recall that a derivation is a sequence of
strings, where each string contains
variables and terminals.
• The first string is always the start symbol
of G and each string is obtained from the
previous one by a single activation of
some rule.

21
Proof Idea (cont.)
• A string may allow activation of several rules
and the PDA P non deterministically guesses
the next rule to be activated.
• The initial idea for the simulation is to store
each intermediate string on the stack.
• Upon each production, the string on the
stack before production is transformed to
the string after production.
22
Proof Idea (cont.)
• Unfortunately, this idea does not quite
work since at any given moment, P can
only access the top symbol on the stack.
• To overcome this problem, the stack
holds only a suffix of each intermediate
string where the top symbol is the
variable to be substituted during the next
production.

23
The Intermediate String aaSbb

Finite control
S
a a a b b b b
b
input $

stack

24
Informal Description of P
• Push the marker $ and the start symbol S
on the stack.
Repeat
• If the top symbol is a variable V – Replace
V by the right hand side of some non
deterministically chosen rule whose left
hand side is V .
…..

25
Informal Description of P
• Push the marker $ and the start symbol S
on the stack.
Repeat
…..
• If the top symbol is a terminal compare it
with the next symbol on the input. If
equal – advance the input and pop the
variable else – reject.
26
Informal Description of P
Push the marker $ and the start symbol S on the
stack.
Repeat
…..
…..
If the top symbol is $ and the input is finished –
accept else – reject

27
The Proof
• We start by defining Extended Transitions:
• Assume that PDA P is in state q , it reads a ∈
Σ from the input and pops s ∈ Γ from the
stack and then moves to state r while
pushing u = u1,u2,…,ul onto the stack.
• This is denoted by (r,u) ∈ δ(q,a,s)
• Next, extended transitions are implemented.

28
Implementing Extended Transitions
• Add states q1, q2, …qi-1 .
• Set the transition function δ as follows:
• Add (q1,u l) to δ(q,a,s)
• Set δ(q1,ε,ε)={(q2,u l−1)},
(δ(q2,ε,ε)={(q3,u l−2)},
...
δ(ql−1,ε,ε)={(r,u1)}.
(see next slide)
29
Implementing Extended Transitions

q q a, s   z
a, s   xyz
q1
r  ,    y
q2
• This extended r  ,    x
transition is
implemented by this
transition sequence
30
The Proof
• Let G be an arbitrary CFG. Now we are ready
to construct the PDA, P such that that L(P)
=L(G).
• The states of P are a Q = {qstart,qloop,qaccept} ∪
E,
• where E contains all states needed to
implement the extended transitions
presented in the previous slide.
• The PDA P is presented on the next slide
31
The Result PDA

Вам также может понравиться