Pushdown Automata
Pushdown automata resemble nondeterministic finite automata but have access to unlimited memory, modeled as a stack that operates on a first-in, last-out (FILO) principle.
Definition. A pushdown automaton is a six-tuple , where
- is a finite set of states,
- is a finite set of input symbols,
- is a finite set of stack symbols,
- is the transition function, where , , and is the power set of ,
- is the start state and
- is a finite set of accept states.
At the core of a pushdown automaton's definition is its transition function. The next move is determined by three elements from the domain :
- The current state.
- The next input symbol :
- If , the machine moves without consuming input.
- The symbol at the top of the stack:
- If , the machine moves without reading or popping the stack.
- Otherwise, the machine pops from the stack.
The machine transitions to a new state and updates the stack based on a pair from the domain :
- It enters a (possibly new) state.
- It may push a symbol onto the stack:
- If , no symbol is written.
Example Operations
If we want the automaton to move to state and push a symbol onto the stack when the machine is in state and reads input , we specify the transition function by including in .
Conversely, if we want the automaton to move to state and pop the symbol on top of the stack when
- the machine is in state ,
- reads input , and
- the symbol on top of the stack is ,
we specify the transition function by including in .
Computation
A pushdown automaton computes as follows. It accepts input if can be written as , where each , and sequences of states and strings exist that satisfy the following three conditions. The strings represent the sequence of stack contents that has on the accepting branch of the computation.
-
and . This condition signifies that starts properly, in the start state with an empty stack.
-
For , we have , where and for some and . This condition states that transitions correctly based on its state, stack, and input symbol.
-
. This condition ensures that reaches an accept state at the end of the input.
What can be computed by Pushdown Automata
Theorem. The class of context-free languages is closed under union, concatenation, and star operations.
What cann't be computed by Pushdown Automata
Pumping Lemma. For every context-free language , there is a number , such that for every , if the length of is greater than , then can be devided into five pieces , satisfying the following three conditions:
- , for all ,
- and
- or .
Context-Free Grammar
Definition. A context-free grammar is a four-tuple , where
- is a finite set of symbols called the variables,
- is a finite set of symbols, disjoint from , called the terminals,
- is the start symbol, and
- is a finite set of rules, with each rule of the form , where and .
Computation. Let .
- Say that yields , written , if there exists a rule of the grammar,
- Say that derives , written , if or if a sequence exists for and
The language of the grammar is .
Chomsky Normal Form. A context-free grammar is in chomsky normal form if each rule is of one of the two forms
- , where , and ,
- , where .
In addition, we permit , where is the start variable.
Equivalence between Context-Free Grammar and Pushdown Automata
-
For every context-free grammar , there is an automaton , such that recognizes the language generated by .
-
If a pushdown automaton recognizes some language, then it is context-free.
Proof: For the convenience of proof, we modify a pushdown automaton to give it three features:
- accepts by entering empty stack.
- These is only one accept state in .
- Each transition either pushes a symbol onto the stack or pops one off the stack, but it does not do both at the same time.
The way to construct a context-free grammar from the push-down automaton is given by follow:
(1) , we put the rule in G.
(2) , we add to a new rule ,
(3) , if , , s.t. and , then we put the rule in .
It is easy to see that (1) and (2) may give rise to many meaningless grammar rules, i.e., grammar rules that will never be used to derive terminal strings. (3) seems to be the only exception at the first glance. However, it indeed does the same. Consider the following example,

Some of the grammar productions constructed according to (1), (2), (3) are:
| grammar productions | contructed according to [(1)/(2)/(3)] |
|---|---|
| [according to (3)] | |
| [according to (2)] | |
| [according to (3)] | |
| [according to (1)] | |
| [according to (2)] | |
| [according to (3)] | |
| [according to (3)] | |
| [according to (1)] | |
| ... | ... |
Heading down this way, we can get the grammar for pushdown automaton .
But following (3), we also get productions like:
These rules are useless. They can not derive any string of terminals. To understand the real cause of the problem, take for example. When the push down automaton goes from state to state , it pushes a into the stack. And a is poped during the transition from state to . But the poped is not the same pushed during the transition from state to . At state , the stack does not recover to its initial state before the automaton entering state . Some additional non-terminal symbols are still in the stack.
Now let's look at another automaton M2 that recognizes the same language as M1.

Interestingly, such unnecessary rules disappear in . See the following rules:
| grammar productions | contructed according to [(1)/(2)/(3)] |
|---|---|
| according to (2) | |
| according to (3) | |
| according to (3) |
When the push down automaton goes from state to state , it pushes a into the stack. And a is poped during the transition from state to . When entering state , the stack may not be what it is before going to state . But the rule is valid. It can indeed derive terminal strings.
Actually, will enter twice, with and in the stack respectively. In the former case, the automaton will loop on . It enters the accept state until is left on the stack.
The grammar corresponding to :
In the book Introduction To Automata Theory, Languages, and Computation, John E. Hopcroft, Rajeev Motwani, Jeffery D. Ullman give another way of converting a pushdown automaton into context-free grammar. In that way, we can avoid construct meaningless rules even for pushdown automaton . The key idea is, rule like is constructed if and only if in state the stack is the same as what it is before the automaton entering state .
One more thing to mention about rule(3)
(3) , if , s.t. and , then we put the rule in G.
is that need not to be . We will give an example, though it is kind of weird.

Reference
[1] Introduction To The Theory Of Computation, 2nd Edition, by Michael Sipser