1 Equivalence of PDA's and CFG'S: 1.1 From Grammar To Pushdown Automata
1 Equivalence of PDA's and CFG'S: 1.1 From Grammar To Pushdown Automata
1 Equivalence of PDA's and CFG'S: 1.1 From Grammar To Pushdown Automata
PDA by PDA by
Grammar empty stack final state
We have already shown that (2) and (3) are the same. Now, we prove that (1) and
(2) are same.
Recall the following theorem from the chapter context-free grammar.
1
with A at the top. At that time, x will be represented by our having consumed x
from the input, leaving whatever of w follows its prefix x. That is, if w = xy, then
y will remain on the input.
Suppose the PDA is in an ID (q, y, Aα), representing left-sentential form xAα. It
guesses the production to use to expand A, say A → β. The move of the PDA is
to replace A on the top of the stack by β, entering ID (q, y, βα). Note that there is
only one state, q, for this PDA.
Now, (q, y, βα) may not be a representation of the next left-sentential form, because
β may have a prefix of terminals. In fact, β may have no variables at all, and α
may have a prefix of terminals. Whatever terminals appear at the beginning of βα
need to be removed, to expose the next variable at the top of the stack. These
terminals are compared against the next input symbols, to make sure our guesses at
the leftmost derivation of input string w are correct; if not, this branch of the PDA
dies.
If we succeed in this way to guess a leftmost derivation of w, then we shall eventually
reach the left-sentential form w. At that point, all the symbols on the stack have
either been expanded (if they are variables) or matched against the input (if they
are terminals). The stack is empty, and we accept by empty stack.
The above informal construction can be maid precise as follows. Let G = (V, T, R, S)
be a CFG. Construct the PDA P that accepts L(G) by empty stack as follows:
P = ({q}, T, V ∪ T, δ, q, S)
where transition function δ is defined by:
2
1.2 From PDA’s to Grammar
The construction of an equivalent grammar uses variables each of which represent
an event consisting of:
2. A change in state from some p at the beginning to q when X has finally been
replaced by on the stack.
1. a is either a symbol in Σ or a = .
2. k be any number, including 0, in which case the pair is (r, ).
Example: Consider the PDA PN = ({q}, {0, 1}, {Z, A, B}, δN , q, Z) in Figure 2.
The corresponding context-free grammar G = (V, {0, 1}, R, S) is given by:
3
V = {S, [qZq], [qAq], [qBq]}.
R=
1. S → [qZq]
2. [qZq] → 0[[qAq][qZq] (since δN (q, 0, Z) contains (q, AZ))
3. [qZq] → 1[[qBq][qZq] (since δN (q, 1, Z) contains (q, BZ))
4. [qAq] → 0[[qAq][qAq] (since δN (q, 0, A) contains (q, AA))
5. [qBq] → 1[[qBq][qBq] (since δN (q, 1, B) contains (q, BB))
6. [qAq] → 1 (since δN (q, 1, A) contains (q, ))
7. [qBq] → 0 (since δN (q, 0, B) contains (q, ))
8. [qZq] → (since δN (q, , Z) contains (q, ))