Download presentation
Presentation is loading. Please wait.
Published byRandolph McDaniel Modified over 9 years ago
1
Pushdown Accepters & Context-Free Grammars Sipser, Theorem 2.12 Denning, Chapter 8
2
Fundamental theorem of CFLs and PDAs Theorem 2.12 (Sipser) A language L is context-free if and only if (iff) there exists a pushdown accepter M that recognizes L
3
CFL if PDA; PDA -> CFL Given a PDA, M, that recognizes language L, then there exists a CFG, G, that generates language L. Proof: Denning, Section 8.4, using traverse sets
4
CFL only if PDA; CFL -> PDA Given a CFL, L, generated by grammar G, we can build a PDA, M, which recognizes language L. Proof: Denning, Section 8.3
5
Proof: CFL -> PDA Since L is context free, there is a context free grammar, G = (N,T,P,S) that generates L. Construct the PDA, M=(Q,T,U,P’,q0,{q3}), as follows: T = same input alphabet U = N T {S} = stack alphabet Q = {q0,q1,q2,q3} {qx | x U}
6
Program of M q0: , push($), goto q1 q1: , push(S), goto q2 q2: , pop($), goto q3 For each production A->w q2: , pop(A), goto qA qA: , push(w R ), goto q2 For each terminal symbol a q2: a, NOP, goto qa qa: , pop(a), goto q2
7
Example: L = {0 k 1 k | k 0} Grammar G has productions: S A; A 01; A 0A1 push $ push S pop S push A pop A push 1 push 0 push A push 0 pop $ in 0 pop 0 in 1 pop 1
8
Ex 2: L={0 j 1 k 2 j+k | j,k > 0} S A; A 0A2; A 0B2; B 12; B 1B2
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.