Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages.

Slides:



Advertisements
Similar presentations
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Advertisements

Chapter 5 Pushdown Automata
1 Pushdown Automata (PDA) Informally: –A PDA is an NFA-ε with a stack. –Transitions are modified to accommodate stack operations. Questions: –What is a.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
Pushdown Automata (PDA)
Pushdown Automata Part II: PDAs and CFG Chapter 12.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Transparency No. 2-1 Formal Language and Automata Theory Chapter 2 Deterministic Finite Automata (DFA) (include Lecture 3 and 4)
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
Transparency No. 4-1 Formal Language and Automata Theory Chapter 4 Patterns, Regular Expressions and Finite Automata (include lecture 7,8,9) Transparency.
Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
Transparency No. P2C1-1 Formal Language and Automata Theory Part II Pushdown Automata and Context-Free Languages.
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
Transparency No. 8-1 Formal Language and Automata Theory Chapter 8 DFA state minimization (lecture 13, 14)
CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Pushdown Automata.
Chapter 7 PDA and CFLs.
Pushdown Automata (PDA) Intro
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Pushdown Automata Part I: PDAs Chapter Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2)
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s Pushdown Automata 11.
Lecture Pushdown Automata. stack stack head finite control tape head tape.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
Grammars A grammar is a 4-tuple G = (V, T, P, S) where 1)V is a set of nonterminal symbols (also called variables or syntactic categories) 2)T is a finite.
C SC 473 Automata, Grammars & Languages Automata, Grammars and Languages Discourse 04 Context-Free Grammars and Pushdown Automata.
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
Formal Languages, Automata and Models of Computation
Transparency No. 4-1 Formal Language and Automata Theory Chapter 4 Patterns, Regular Expressions and Finite Automata (include lecture 7,8,9) Transparency.
Lecture 14UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 14.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
Lecture 6: Context-Free Languages
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
CS 154 Formal Languages and Computability March 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
1 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations pop, push, and nop. PDAs always.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Theory of Computation Pushdown Automata pda Lecture #10.
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata Reading: Chapter 6.
Pushdown Automata and Context-Free Languages
Presentation transcript:

Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages

PDAs and CFLs Transparency No. P2C3-2 NPDAs A NPDA (Nondeterministic PushDown Automata) is a 7-tuple M = (Q, , , ,s, , F) where Q is a finite set (the states)  is a finite set (the input alphabet)  is a finite set (the stack alphabet)   (Q x (  U {  })x  ) x (Q x  *) is the transition relation s  Q is the start state    is the initial stack symbol F  Q is the final or accept states ((p,a,A),(q,B 1 B 2 …B k ))   means that whenever the machine is in state p reading input symbol a on the input tape and A on the top of the stack, it pops A off the stack, push B 1 B 2 …B k onto the stack (B k first and B 1 last), move its read head right one cell past the a and enter state q. ((p, ,A),(q,B 1 B 2 …B k ))   means similar to ((p,a,A),(q,B 1 B 2 …B k ))   except that it need not scan and consume any input symbol.

PDAs and CFLs Transparency No. P2C3-3 Configurations Collection of information used to record the snapshot of an executing NPDA an element of Q x  * x  *. Configuration C = (q, x, w) means the machine is at state q, the rest unread input string is x, the stack content is w. Example: the configuration (p, baaabba, ABAC  ) might describe the situation: A B A C  a b a b b a a a b b a p

PDAs and CFLs Transparency No. P2C3-4 Start configuration and the next configuration relations Given a NPDA M and an input string x, the configuration (s, x,  ) is called the start configuration of NPDA on x. CF M = def Q x  * x  * is the set of all possible configurations for a NPDA M. One-step computation of a NPDA: (p, ay, A  ) --> (q, y,  ) if ((p,a,A), (q,  ))  . (1) (p, y, A  ) --> (q, y,  ) if ((p, ,A),(q,  ))  . (2) Let the next configuration relation --> M on CF M 2 be the set of pairs of configurations satisfying (1) and (2). --> M describes how the machine can move from one configuration to another in one step. (i.e., C --> M D iff D can be reached from C by executing one instruction) Note: NPDA is nondeterministic in the sense that for each C there may exist multiple D’s s.t. C --> M D.

PDAs and CFLs Transparency No. P2C3-5 Multi-step computations and acceptance Given a next configuration relation --> M : Define ---> n M and --->* M as usual, i.e., C --> 0 M D iff C = D. C --> n+1 M iff  E C--> n M E and E--> M D. C -->* M D iff  n  0 C --> n M D. i.e., --->* M is the ref. and trans. closure of --> M. Acceptance: When will we say that an input string x is accepted by an NPDA M? two possible answers: 1. by final states: M accepts x ( by final state) iff (s,x,  ) -->* M (p, ,  ) for some final state p  F. 2. by empty stack: M accepts x by empty stack iff (s,x,  ) -->* M (p, ,  ) for any state p. Remark: both kinds of acceptance have the same expressive power.

PDAs and CFLs Transparency No. P2C3-6 Language accepted by a NPDAs M = (Q, ,s,,F) : a NPDA. The languages accepted by M is defined as follows: 1. accepted by final state: L f (M) = {x | M accepts x by final state} 2. accepted by empty stack: L e (M) = {x | M accepts x by empty stack}. 3. Note: Depending on the context, we may sometimes use L f and sometimes use L e as the official definition of the language accepted by a NPDA. I.e., if there is no worry of confusion, we use L(M) instead of L e (M) or L f (M) to denote the language accepted by M. 4. In general L e (M)  L f (M).

PDAs and CFLs Transparency No. P2C3-7 Some example NPDAs Ex 23.1 : M 1 : A NPDA accepting the set of balanced strings of parentheses [ ] by empty stack. M 1 requires only one state q and behaves as follows: 1. while input is ‘[‘ : push ‘[‘ onto the stack ; 2. while input is ‘]’ and top is ‘[’ : pop 3. while input is ‘  ’ and top is  pop. Formal definition: Q = {q},  = {[,]},  = {[,  }, start state = q, initial stack symbol = .  = { ( (q,[,  ), (q, [  ) ), ( (q,[, [), (q, [[) ), // 1 ( (q,], [), (q,  ) ), // 2 ( (q, ,  ), (q,  ) ) } // 3 Transition Diagram representation of the program  : ==> ? This machine is not deterministic. Why ?

PDAs and CFLs Transparency No. P2C3-8 Example execution sequences of M1: let input x = [ [ [ ] ] [ ] ] [ ]. Then below is a successful computation of M 1 on x: (q, [ [ [ ] ] [ ] ] [ ],  ) : the start configuration --> M (q, [ [ ] ] [ ] ] [ ], [  ) instruction or transition (i) --> M (q, [ ] ] [ ] ] [ ], [ [  ) transition (ii) --> M (q, ] ] [ ] ] [ ], [ [ [  ) transition (ii) --> M (q, ] [ ] ] [ ], [ [  ) transition (iii) --> M (q, [ ] ] [ ], [  ) transition (iii) --> M (q, ] ] [ ], [ [  ) transition (ii) --> M (q, ] [ ], [  ) transition (iii) --> M (q, [ ],  ) transition (iii) --> M (q, ], [  ) transition (i) --> M (q,,  ) transition (iii) --> M (q,, ) transition (iv) accepts by empty stack

PDAs and CFLs Transparency No. P2C3-9 Failure computation of M1 on x Note besides the above successful computation, there are other computations that fail. Ex: (q, [ [ [ ] ] [ ] ] [ ],  ) : the start configuration -->* M (q, [ ],  ) --> M (q, [ ], ) transition (iv) a dead state at which the input is not empty and we cannot move further ==> failure!! Note: For a NPDA to accept a string x, we need only one successful computation (i.e.,  D with empty input and stack s.t. (s,x,  ) -->* M D. ) Theorem: String x  {[,]}* is balanced iff it is accepted by M 1 by empty stack. Pf: direct result of the key lemma: For any string y, if L(z)  R(z) for all prefixes z of y=zx, then (q, zx,  ) -->*(q,x, [ L(z)-R(z)  )

PDAs and CFLs Transparency No. P2C3-10 Another example The set {ww | w  {a,b}*} is known to be not Context-free but its complement L 1 = {a,b}* - {ww | w  {a,b}*} is. Exercise: As specified at p 147, design a NPDA to accept L 1 by empty stack. Hint: x  L 1 iff (1) |x| is odd or (2) x = yazybz’ or ybzyaz’ for some y,z,z’  {a,b}* with |z|=|z’|, which also means x = yay’ubu’ or yby’uau’ for some y,y’,u,u’  {a,b}* with |y|=|y’| and |u|=|u’|.

PDAs and CFLs Transparency No. P2C3-11 Equivalent expressive power of both types of acceptance M = (Q, , , ,s,,F) : a PDA Let u, t : two new states  Q and  : a new stack symbol  . Define a new PDA M’ = (Q’, ,  ’,  ’,s’, , F’) where Q’ = Q U {u, t},  ’ =  U {  }, s’ = u, F’ = {t} and  ’ =  U { (u, ,  ) --> (s,  ) } // push  and call M U { (f, , A) -> (t,A) | f  F and A   ’ } /* return to M’ if entering into final states */ U {(t, ,A) --> (t,  ) | A   ’ } // pop until EmptyStack Diagram form relating M and M’: Theorem: L f (M) = L e (M’) pf: M accepts x => (s, x,  ) --> n M (q, ,  ) for some q  F => (u, x,  ) --> M’ (s, x,  ) --> n M’ (q, ,  ) --> M’ (t, ,   ) -->* M’ (t, ,  ) => M’ accepts x by empty stack.

PDAs and CFLs Transparency No. P2C3-12 From final state to emptystack: M s f u t ( , ,  ) * ( ,A,A) + for all As ( ,A,  ) ++ for all As M’ *: push  and call M +: return to t of M’ if entering into final states ++: pop all stack symbols until emptystack

PDAs and CFLs Transparency No. P2C3-13 From FinalState to EmptyStack Conversely, M’ accepts x by empty stack => (u, x,  ) --> M’ (s, x,  ) -->* M’ (q, y,   ) --> (t, y,  ) -->* (t, ,  ) for some q  F => y =  since M’ cannot consume any input symbol once it enters into state t. => M accepts x by final state. Define next new PDA M’’ = (Q’, ,  ’,  ’’,s’, , F’) where Q’ = Q U { u, t},  ’ =  U {  }, s’ = u, F’ = {t} and  ’’ =  U { (u, ,  ) --> (s,  ) } // push  and call M U { (p, ,  ) -> (t,  ) | p  Q } /* return to M’’ and accept if EmptyStack */ Diagram form relating M and M’’:

PDAs and CFLs Transparency No. P2C3-14 From EmptyStack to FinalState Theorem: L e (M) = L f (M’’). pf: M accepts x => (s, x,  ) --> n M (q, ,  ) => (u, x,  ) --> M’’ (s, x,  ) --> n M’’ (q, ,   ) --> M’’ (t, ,  ) => M’’ accepts x by final state (and empty stack). Conversely, M’’ accepts x by final state (and empty stack) => (u, x,  ) --> M’’ (s, x,  ) -->* M’’ (q, y,  ) --> M’’ (t, ,  ) for some state q in Q => y =  [and STACK=  ] since M’’ does not consume any input symbol at the last transition ((q, ,  ), (t,  )) => M accepts x by empty stack. QED

PDAs and CFLs Transparency No. P2C3-15 From emptystack to final state (and emptystack) M s f u t ( , ,  ) * ( , ,  ) + M’’ ( , ,  ) + * : push  and call M +: if emptystack (i.e.see  on stack), then pop  and return to state t of M’’

PDAs and CFLs Transparency No. P2C3-16 Equivalence of PDAs and CFGs Every CFL can be accepted by a PDA. G = (N, ,P,S) : a CFG. wlog assume all productions of G are of the form: A -> c B  B 2 B 3 …B k ( k  0) and c   U {  }. note: 1. A ->  satisfies such constraint; 2. can require k  2. Define a PDA M = ({q}, , N, , q, S, {}) from G where q is the only state (hence also the start state), , the set of terminal symbols of G, is the input alphabet of M, N, the set of nonterminals of G, is the stack alphabet of M, S, the start nonterminal of G, is the initial stack symbol of M, {} is the set of final states. (hence M accepts by empty stack!!)  = { ((q,c,A), (q, B 1 B 2 …B k )) | A -> c B  B 2 B 3 …B k  P }

PDAs and CFLs Transparency No. P2C3-17 Example G : S -> [ B S(q, [, S) --> (q, B S) S -> [ B(q, [, S) --> (q, B ) S-> [ S B ==>  : (q, [, S) --> (q, S B) S -> [ S B S (q, [, S) --> (q, S B S) B -> ] (q, ], B) --> (q,  ) L(G) = the set of nonempty balanced parentheses. leftmost derivation v.s. computation sequence (see table at p 153) S L -->* G [ [ [ ] ] [ ] ] (q, [[[]][]], S) -->* M (q, ,  )

PDAs and CFLs Transparency No. P2C3-18 leftmost derivation v.s. computation sequence Lemma 24.1: For any z,y   *,   N* and A  N, A L --> n G z  iff (q, zy, A) --> n M (q, y,  ) Ex: S L --> 3 G [ [ [ BBSB (q, [[[ ]][]], S) --> 3 M (q, ]][]], BBSB) pf: By ind. on n. Basis: n = 0. A L --> 0 G z  iff z =  and  = A iff (q, zy, A) = (q, y,  ) iff (q, zy, A) --> 0 M (q,y,  ) Ind. case: 1. (only-if part) Suppose A L --> n+1 G z  and B -> c  was the last rule applied. I.e., A L --> n G uB  L --> G uc  = z  with z = uc and . Hence (q, u cy, A ) --> n M (q, cy, B  ) // by ind. hyp. --> M (q, y,  ) // since ((q,c,B),(q,  ))  

PDAs and CFLs Transparency No. P2C3-19 leftmost derivation v.s. computation sequence (cont’d) 2. (if-part) Suppose (q, zy, A) --> n+1 M (q, y,  ) and ((q,c,B),(q,  ))   is the last transition executed. I.e., (q, zy, A) --> n M ( q, cy,  ) --> M (q, y,  ) with  and z = uc for some u. But then A L --> n G uB  // by ind. hyp., L --> uc  = z  // since by def. B -> c   P Hence A L --> n+1 G z  QED Theorem 24.2: L(G) = L(M). pf: x  L(G) iff S L -->* G x iff (q, x, S) -->* M (q,  ) iff x  L(M). QED

PDAs and CFLs Transparency No. P2C3-20 Simulating PDAs by CFGs Claim: Every language accepted by a PDA can be generated by a CFG. Proved in two steps: 1. Special case : Every PDA with only one state has an equivalent CFG 2. general case: Every PDA has an equivalent CFG. Corollary: Every PDA can be minimized to an equivalent PDA with only one state. pf: M : a PDA with more than one state. 1. apply step 2 to find an equivalent CFG G 2. apply theorem 24.2 on G, we find an equivalent PDA with only one state. Q.E.D

PDAs and CFLs Transparency No. P2C3-21 PDA with only one state has an equivalent CFG. M = ({s}, , , , s, , {}) : a PDA with only one state. Define a CFG G = ( , , P,  ) where P = { A -> c  | ((q, c, A), (q,  ))   } Pf: M ==> G is just the inverse of the transformation : G ==> M defined at slide 15. Theorem: L(G) = L(M). Pf: Lemma 24.1 and Theorem 24.2 and their proofs are all valid to the present G and M. QED

PDAs and CFLs Transparency No. P2C3-22 Simulating general PDAs by CFGs How to simulate arbitrary PDA by CFG ? idea: encode all state information by nonterminals !! Wlog, assume M = (Q, , , , s, , {t}) be a PDA with only one final state and M can empty its stack before it enters its final state. Let  = Q x   x Q. Elements of N are written as. Define a CFG G = (N, ,, P ) where P = {  c | ((p,c,A), (q, B 1 B 2 …B k ))   k  c   U  r  Q } + rules for nonterminals

PDAs and CFLs Transparency No. P2C3-23 Rules for We want to simulate the computation process in PDA M: (q, wy, B 1 B 2 …B k ) |-…|- (r, y,  ) iff  * w. Hence: if k = 0. ie., =   if q = r and has no rule if q≠r. If k > 1. Let B 1 B 2 …B k = B 1  2, then :   u1 ∈ Q   u1 ∈ Q  u2 ∈ Q  …   u1 ∈ Q  u2 ∈ Q … …

PDAs and CFLs Transparency No. P2C3-24 (p, c, A) --> (q, B 1 B 2...B k ) A C  p c x 1 x 2... t t1 t2 t1 p B k-1 BkBk C  q c x 1 x 2... B1B1 B2B2 t t1 t2 q k= t 2 q k-1 q1q1 q1q1 q2q2 q2q2.... q We want to use  * w to simulate the computation: (p, wy, A)  * M (q, y,  ) So, if (p,c,A)  M (q,  ) we have rules :  c for all states r.

PDAs and CFLs Transparency No. P2C3-25 How to derive the rule  c ? How to derive rules for the nonterminal : case 1:  = B 1 B 2 B 3 …B n ( n > 0) => = =>  … for all states q 1,q 2,…,q n-1 in Q. case2:  = . q = r => =  . q != r => cannot derive any string. Then  c = c.

PDAs and CFLs Transparency No. P2C3-26 Simulating PDAs by single-state PDAs (cont’d) Note: Besides storing sate information on the nonterminals, G simulate M by guessing nondeterministically what states M will enter at certain future points in the computation, saving its guesses on the sentential form, and then verifying later that those guesses are correct. Lemma 25.1: (p,x,B 1 B 2 …B k ) --> n M (q,  ) iff  q 1,q 2,…q k-1 such that … L  n G x. (*) Note: 1. when k = 0 (*) is reduced to L  n G x 2. In particular, (p,x,B) --> n M (q,  ) iff L  n G x. Pf: by ind. on n. Basis: n = 0. LHS holds iff ( x = , k = 0, and p = q ) iff RHS holds.

PDAs and CFLs Transparency No. P2C3-27 Simulating PDAs by single-state PDAs (cont’d) Inductive case: (=>:) Suppose (p,x,B 1 B 2 …B k ) --> n+1 M (q,  ) and ((p,c,B 1 ),(r,C 1 C 2 …C m )) is the first instr. executed. I.e., (p,x,B 1 B 2 …B k ) --> M (r, y  C 1 C 2 …C m B 2 …B k )  --> n M (q,  ), where x = cy. By ind. hyp.,  states  r   r m-1,(r m = q 1 ), q 2,… q k-1 with... … L  n G y Also by the definition of G:  c... is a rule of G. Combining both, we get: … L  G c... … L  n G c y ( = x ).

PDAs and CFLs Transparency No. P2C3-28 Simulating PDAs by CFGs (cont’d) ( … L  n+1 G x. Let  c...  P --(*) be the first rule applied. i.e., Then … L  G c... … L  G n cy ( = x ) But then since, by (*), [(p, c, B1), (r 0, C 1 C 2 …C m )] – (**) is an instr of M, (p,x,B 1 …B k ) --> M (r 0, y, C 1 C 2 …C m B 2 …B n ) --- By (**) --> n M (q,  ). --,by ind. hyp. QED Theorem 25.2 L(G) = L(M). Pf: x  L(G) iff  * x iff (s,x,  ) -->* M (t,  ) ---- Lemma 25.1 iff x  L(M). QED

PDAs and CFLs Transparency No. P2C3-29 Example L = {x  {[,]}* | x is a balanced string of [ and ]], i.e., #](x) = 2 #[(x) and all “[“s must occur in pairs } Ex: [ ]] [ [ ]] ]] ∈ L but [ ] [ ] ]] ∉ L. L can be ac ce pted by the PDA M = (Q, , , , p, ,{t} ), where Q = {p,q,t},  = {[,]},  = {A, B, , and  is given as follows: (p, [,  ) --> (p, A  ), (p,[,A) --> (p,AA), (p, ], A) --> (q,  ), (q, ], B) --> (p,  ), (p, ,  ) --> (t,  ) t q p ,B/  ,/,/ [,A/AA [,  /A  ,A/ 

PDAs and CFLs Transparency No. P2C3-30 M can be simulated by the CFG G = (N, ,, P) where N = { | X,Y  {p,q,t} and D  { A,B,  } }, and P is derived from the following pseudo rules : (p, [,  ) --> (p, A  ) :  [ (p,[,A) --> (p,AA) :  [ (p, ], A) --> (q, B), :  ] This produce 3 rules ( ? = p or q or t ). (q, ], B) --> (p,  ), :  ] This produces 1 rule : ( ? = p, but could not be q or t why ?)  ]   ]  ] (p, ,  ) --> (t,  ) :  This results in   (since  . )

PDAs and CFLs Transparency No. P2C3-31  [  resulting in 3 rules : ? = p, q or t.  [ ---(1)  [ ---(2)  [ ---(3) (1)~(3) each again need to be expanded into 3 rules.  where ? is p or q or t.  [ resulting in 9 rules: Where ? 2 = p,q, or t.  [ ---(1)  [ ---(2)  [ ---(3)