2. Equivalence of PDA and CFL
If a grammar G is context-free, we can build an
equivalent nondeterministic PDA which accepts
the language that is produced by the context-free
grammar G. A parser can be built for the
grammar G.
Also, if P is a pushdown automaton, an equivalent
context-free grammar G can be constructed where
L(G) = L(P)
21 November 2017
Sampath Kumar S, AP/CSE, SECE
2
3. Application:
This equivalence allows a CFG to be used to
specify a programming language and the
equivalent PDA to be used to implement its
compiler.
21 November 2017
Sampath Kumar S, AP/CSE, SECE
3
4. Theorem
Theorem: A language is context-free iff some
pushdown automaton recognizes it.
Note:
This means that:
1. If a language L is context-free then there is a
PDA ML that recognizes it
2. If a language L is recognized by a PDA ML then
there is a CFG GL that generates L.
21 November 2017
Sampath Kumar S, AP/CSE, SECE
4
5. CFG to PDA Conversion:
PDA accepts CFL
CFL is generated by CFG
If CFG is given to us then we can construct a PDA
which will accept the language generated by this
grammar.
CFG G can be defied as G= (N, T, P, S) and M is
a PDA
M accepts the language generated by G by empty
stack
21 November 2017
Sampath Kumar S, AP/CSE, SECE
5
6. CFG to PDA Conversion procedure:
Input −A CFG, G= (V, T, P, S)
Output −Equivalent PDA, M= (Q, ∑, S, δ, q0, I, F)
Step 1: Convert the productions of the CFG into GNF.
Step 2: The PDA will have only one state {q}.
Step 3: The start symbol of CFG will be the start symbol
in the PDA M.
Step 4: All non-terminals of the CFG will be the stack
symbols of the PDA and all the terminals of the CFG
will be the input symbols of the PDA.
Step 5: For each production A → aX where a is terminal
and A, X are combination of non-terminals, make a
transition δ (q, a, A) = (q, X)
21 November 2017
Sampath Kumar S, AP/CSE, SECE
6
7. Problem to discuss:
125. Construct a PDA from the following CFG.
G = ({S, X}, {a, b}, P, S) where the production P are −
S → aA2|aA3
A2 → aA2A3|aA3A3
A3 → b
Solution
Let the equivalent PDA,
P = ({q}, {a, b}, {a, b, S, A2, A3 }, δ, q,
S)
where δ −
δ(q, a, S) = {(q, A2), (q, A3)}
δ(q, a, A2) = {(q, A2A3),(q, A3 A3)}
δ(q, b, A3) = {(q, ε )}
21 November 2017
Sampath Kumar S, AP/CSE, SECE
7