Professional Documents
Culture Documents
CFG Pda Equivalence
CFG Pda Equivalence
Siu On CHAN
Fall 2018
Chinese University of Hong Kong
1/12
CFGs and PDAs
context-free pushdown
grammar automaton
2/12
Convention
will be abbreviated as
x, a/bcd
q0 q1
3/12
Converting a CFG to a PDA
Idea: Use PDA to simulate derivations
A → 0A1
Example: A→B
A ⇒ 0A1 ⇒ 00A11 ⇒ 00B11 ⇒ 00#11 B→#
Rules:
4/12
Converting a CFG to a PDA
Idea: Use PDA to simulate derivations
A → 0A1
Example: A→B
A ⇒ 0A1 ⇒ 00A11 ⇒ 00B11 ⇒ 00#11 B→#
Rules:
CFG
ε, ε/$A ε, $/ε
q0 q1 q2
A → 0A1
A→B ε, A/1A0 0, 0/ε
ε, A/B 1, 1/ε
B→# ε, B/# #, #/ε
5/12
General CFG to PDA conversion
a, a/ε ε, A/αk . . . α1
for every terminal a for every production
A → α1 . . . αk
q0 q1 q2
ε, ε/$A ε, $/ε
6/12
From PDAs to CFGs
context-free pushdown
grammar automaton
simplified
PDA
7/12
Simplifying the PDA
q1 q1 ε, ε/ε
ε, ε/ε
=⇒
q2 q3 q2 q3 ε, ε/ε
8/12
Simplifying the PDA
9/12
Simplified PDA to CFG
For every pair (q, r) of states in PDA, introduce variable Aqr in CFG
Intention:
Aqr generates all strings that allow the PDA to go from q to r
(with empty stack both at q and at r)
10/12
Simplified PDA to CFG
PDA CFG
q Aqq → ε
a, ε/x
p q Aps → aAqr b
a = ε or b = ε
r s
b, x/ε allowed
11/12
Example: Simplified PDA to CFG
0, ε/ 0 1, ε/1
0, 1/ε 1, 0/ε start variable:
productions:
12/12
Example: Simplified PDA to CFG
12/12
Example: Simplified PDA to CFG
12/12