Download presentation
Presentation is loading. Please wait.
Published byMartin Simpson Modified over 6 years ago
1
Push-down Automata Section 3.3 Wed, Oct 27, 2004
2
Push-Down Automata Recall that DFAs accept regular languages.
We want to design machines similar to DFAs that will accept context-free languages. These machines will need to be more powerful. To handle a language like {anbn | n 0}, the machine needs to “remember” the number of as. To do this, we use a stack. A push-down automaton (PDA) is essentially an NFA with a stack.
3
Definition of a Push-Down Automaton
A push-down automaton (PDA) is a sextuple (K, Σ, Γ, Δ, s, F) where K is a finite set of states. Σ is a finite alphabet of tape symbols. Γ is a finite alphabet of stack symbols. s K is the start state. F K is the set of final states. Δ is the transition relation, i.e., Δ is a finite subset of (K (Σ {e}) Γ*) (K Γ*).
4
Transitions Let ((p, a, β), (q, γ)) Δ be a transition.
It means that we Start in state p. Read a from the tape, Pop the string β from the stack, Move to state q, Push string γ onto the stack. The first three (p, a, β), are “input.” The last two (q, γ) are “output.”
5
Transitions We will draw it as p q a, ;
6
Pushing and Popping When we push β, we push the symbols of β as we read them right to left. When we pop γ, we pop the symbols of γ as we read them from left to right (reverse order). When we push the string abc, we push c, then push b, then push a, i.e., a is on top. When we pop the string abc, we pop a, then pop b, then pop c. Thus, if we push the string abc and then pop it, we will get back abc, not cba.
7
Configurations A configuration fully describes the current “state” of the PDA. The current state. The remaining input. The current stack contents. Thus, a configuration is a triple (p, w, ) (K, *, *).
8
Computations A configuration (p, w, ) yields a configuration (p', w', ') in one step, denoted (p, w, ) (p', w', '), if there is a transition ((p, a, ), (p', )) Δ such that w = aw', = , and ' = for some *. The reflexive, transitive closure of is denoted *.
9
Accepting Strings After processing the string on the tape,
The PDA is in either a final or a nonfinal state, and The stack is either empty or not empty. The input string is accepted if The ending state is a final state, and The stack is empty. That is, the string w * is accepted if (s, w, e) * (p, e, e) for some p F.
10
Example of a PDA Run the following PDA on the input string aaabbb. s p
q a, e; a b, a; e
11
Example of a PDA The steps in the processing are
(s, aaabbb, e) (p, aabbb, a) (p, abbb, aa) (p, bbb, aaa) (p, bb, aa) (p, b, a) (q, e, e).
12
L(A) = {w *A accepts w}.
The Language of a PDA The language of a PDA A is L(A) = {w *A accepts w}. What is the language of the PDA in the previous example?
13
Example of a PDA What is the language of the following PDA? s p
e, e; e b, a; e a, e; a
14
Examples of PDAs Design a PDA that accepts the language
{wcwR | w {a, b}*}. {wwR | w {a, b}*}.
15
Examples of PDAs Design a PDA whose language is {ambn 0 m < n}.
{ambn 0 n < m}.
16
Examples of PDAs Design a PDA whose language is
{ambncndm | m 0, n 0}. {ambmcndn | m 0, n 0}. {ambncpdq | m + n = p + q}. {ambnck | m = n or m = k}.
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.