COMS W3261
Computer Science Theory
Lecture 12: October 19, 2009
Pushdown Automata
1. Outline
- Review
- Pushdown automata (PDA)
- Instantaneous descriptions of PDA's
- The language of a PDA
2. Review
- Parse trees
- Examples of context-free grammars
- Ambiguity
3. Pushdown Automata
- A pushdown automaton is an ε-NFA with a pushdown stack (last-in,
first-out stack).
- Pushdown automata define exactly the context-free languages.
- There are seven components to a PDA P =
(Q, Σ, Γ, δ, q0, Z0, F):
- Q is a finite set of states.
- Σ is a finite set of input symbols (the input alphabet).
- Γ is a finite set of stack symbols (the stack alphabet).
- δ is a transition function from
(Q × Σ ∪ {ε}, Γ) to subsets of
(Q × Γ*):
- Suppose δ(q, a, X) contains (p, γ). Then whenever P is in
state q, looking at the input symbol a with X on top of the stack,
P may go into state p, move to the next input symbol, and replace
X on top of the stack by the string γ.
- The second component, a, may be ε in which case P
makes the move without looking at the input symbol and
does not move to the next input symbol.
- Note that P is nondeterministic so there may be more than one pair
in δ(q, a, X).
- q0 is the start state.
- Z0 is the start stack symbol.
- F is the set of final (accepting) states.
4. Instantaneous Descriptions
- We can represent a configuration of the PDA P above by a triple
(q, w, γ) where:
- q is the state of the finite-state control.
- w is the string of remaining input symbols.
- γ is the string of symbols on the stack. If γ = XYZ,
then X is on top of the stack.
- Suppose δ(q, a, X) contains (p, α). Then
to represent a single move of P we write
- (q, aw, Xβ) |– (p, w, αβ)
- for all strings w in Σ* and β in Γ*.
-
- Note that a may be empty.
5. The Language of a PDA
- A PDA P =
(Q, Σ, Γ, δ, q0, Z0, F)
can define a language two ways.
- Acceptance by final state: P can accept an input string w by
reading all of it and entering a final state:
- Formally, we define L(P), the language accepted by P by final state, to be
the set of input strings w such that P can go from its initial ID
(q0, w, Z0) in a sequence of zero or more moves
to an accepting ID of the form (q, ε, α) where q is a final
state and α is any stack string (perhaps empty).
- Acceptance by empty (null) stack: P can accept an input string by reading
all of it and emptying its stack empty:
- Formally, we define N(P), the language accepted by P by empty stack, to be
the set of input strings w such that P can go from its initial ID
(q0, w, Z0) in a sequence of zero or more moves
to an accepting ID of the form (q, ε, ε) for any state q.
- These two modes of acceptance are equivalent. That is, L has a PDA
that accepts it by final state iff L has a PDA that accepts it by empty stack.
6. Practice Problems
- Construct a PDA that accepts {
wcwR | w
is any string of a's and b's } by final state.
- Construct a PDA that accepts {
wcwR | w
is any string of a's and b's } by empty stack.
- Construct a PDA that accepts {
wwR | w
is any string of a's and b's } by final state.
- Construct a PDA that accepts {
wwR | w
is any string of a's and b's } by empty stack.
7. Reading Assignment
aho@cs.columbia.edu