Equivalence with context-free grammars I Language context free ⇔ recognized by pushdown automata For the left-hand side, recall that by definition a language is context-free if it is constructed by some CFG For the proof, one direction is easier, while the other is harder As usual, we do the easier one first October 12, 2020 1 / 7
CFL → PDA I Given a CFG, we find a PDA to simulate this grammar Two keys: stack nondeterminism: different substitutions We do the proof by an example Suppose we are given the following CFG S → aTb | b T → Ta | ǫ October 12, 2020 2 / 7
CFL → PDA II Idea: for rule substitution, push right-hand side to stack For example, aTb is pushed to stack in a reversed way A PDA can be as follows October 12, 2020 3 / 7
CFL → PDA III q s ǫ, ǫ → a ǫ, ǫ → $ ǫ, ǫ → T ǫ, ǫ → S ǫ, S → b ǫ, S → b ǫ, T → ǫ q loop a , a → ǫ ǫ, T → a b , b → ǫ ǫ, $ → ǫ q a ǫ, ǫ → T October 12, 2020 4 / 7
CFL → PDA IV Consider an example sequence aaaab October 12, 2020 5 / 7
CFL → PDA V ǫ ǫ ǫ q start → q loop , { S , $ } → q 1 , { b , $ } → q 2 , { T , b , $ } a ǫ → q loop , { a , T , b , $ } → q loop , { T , b , $ } ǫ ǫ → q 3 , { a , b , $ } → q loop , { T , a , b , $ } ǫ ǫ → q 3 , { a , a , b , $ } → q loop , { T , a , a , b , $ } ǫ ǫ → q 3 , { a , a , a , b , $ } → q loop , { T , a , a , a , b , $ } a ǫ → q loop , { a , a , a , b , $ } → q loop , { a , a , b , $ } a a → q loop , { a , b , $ } → q loop , { b , $ } b ǫ → q loop , { $ } → q accept October 12, 2020 6 / 7
CFL → PDA VI Even with a non-deterministic setting, we ensure that only strings generated by this CFG can be accepted by the PDA A string is accepted only if all characters are 1 processed We have $ to ensure that the stack is empty in 2 the end October 12, 2020 7 / 7
Recommend
More recommend