10. PDAs and CFGs
Feb 8-10, 2022
PDA CFG
Prove in two directions:
-
PDA
CFGConvert any context-free grammar
to a PDA withTake any arbitrary CFG
, conversion procedure:- for each production
in , add transition: - for each terminal
in , add transition:
Example:GRAMMAR ε,S → aSTb S → aSTb ε,S → b S → b ε,T → Ta T → Ta ε,T → ε T → ε a,a → ε b,b → ε ε,ε → S ⮏ ε,$ → $ -→ ( q0 ) -----------------> ( q1 ) ---------------------> 《 q2 》
In general we can show that grammar
generates string iff and only if PDA accepts .
- for each production
-
PDA
CFGConvert any PDA
to a context-free grammar withTake any arbitrary PDA
, modify PDA so that:- the PDA has a single accept state
- use new initial stack symbol
#
(not used in any transitions) - On acceptance the stack contains only stack symbol
#
- Each transition either pushes a symbol or pops a symbol but not both together
Using this modified PDA, construct the grammar
Denoting variables:
where are states of PDAfor each state , grammarfor every 3 states for every pair of transitions Initial state and accept stateStart variable
Proving L(G) = L(M)
-
We need to show that if
has derivation there is an accepting computation in with input string . Will actually show that if has derivation , then there is a computation in .Since there is no transition with
#
symbol: => =>If
(string of terminals) then there is a computation from state to state on string which leaves the stack empty:Can formally prove this claim by induction on the number of steps in derivation:
where " " represents the number of steps.
Base case: one derivation step
means
kind production must have been used, therefore and . This computation of PDA trivially exists: .Inductive step:
derivation stepssuppose for
steps holds. For steps, show that holds.case 1:
, we can write then - at most steps, and from IH - at most steps, and from IHThen
, and since , .case 2:
, we can write at most steps. From IH, PDA has computation . Grammar contains production and PDA contains transitions: => =>
We know:
=>We also know:
andTherefore:
Since
, . -
The proof for this direction works the same way as the previous inductive proof.
Therefore