Last Lecture We began to show CFL = PDA

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

1 Pushdown Automata (PDA) Informally: –A PDA is an NFA-ε with a stack. –Transitions are modified to accommodate stack operations. Questions: –What is a.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Pushdown Automata (PDA)
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
CS5371 Theory of Computation
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
1 Converting NPDAs to Context-Free Grammars. 2 For any NPDA we will construct a context-free grammar with.
Fall 2004COMP 3351 NPDA’s 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.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
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.
Closure Properties Lemma: Let A 1 and A 2 be two CF languages, then the union A 1  A 2 is context free as well. Proof: Assume that the two grammars are.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
Formal Languages, Automata and Models of Computation
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
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,
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Context-Free Languages & Grammars (CFLs & CFGs) (part 2)
Formal Languages, Automata and Models of Computation
Pushdown Automata.
Closed book, closed notes
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
Context-Free Languages & Grammars (CFLs & CFGs)
PDAs Accept Context-Free Languages
CSE 105 theory of computation
Theorem 29 Given any PDA, there is another PDA that accepts exactly the same language with the additional property that whenever a path leads to ACCEPT,
NPDAs Accept Context-Free Languages
CSE 105 theory of computation
Pushdown Automata (PDA). Part 2
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
PDAs Accept Context-Free Languages
Chapter 7 PUSHDOWN AUTOMATA.
Lecture 17 Oct 25, 2011 Section 2.1 (push-down automata)
Pushdown Automata (PDA)
NPDAs Accept Context-Free Languages
Pushdown Automata Reading: Chapter 6.
Lecture 14 Grammars – Parse Trees– Normal Forms
Context-Free Languages
Chapter Thirteen: Stack Machines
Context-free Languages
Compiler Design 7. Top-Down Table-Driven Parsing
فصل دوم Context-Free Languages
CSCE 531 Compiler Construction
The Pumping Lemma for CFL’s
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
CS21 Decidability and Tractability
Theory of Computation Lecture #
CS21 Decidability and Tractability
… NPDAs continued.
CSE 105 theory of computation
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Conversion of CFG to PDA Conversion of PDA to CFG
CSE 105 theory of computation
Normal Forms for Context-free Grammars
Push Down Automata Push Down Automata (PDAs) are L-NFAs with stack memory. Transitions are labeled by an input symbol together with a pair of the form.
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

Last Lecture We began to show CFL = PDA Theorem 1. Every context-free language is accepted by some PDA. Theorem 2. For every PDA M, the language L(M) is context-free. We showed how a PDA could be constructed from a CFL. Given a CFG G=(V,T,P,S), we define a PDA M=({q},T, T È V, d,q,S), with d given by If A Î V, then d(q,L,A) = { (q,a) | A ® a is in P} If a Î T, then d(q,a,a) = { (q,L) } The stack symbols of the new PDA contain all the terminal and non-terminals of the CFG There is only 1 state in the new PDA Add transitions on L, one for each production Add transitions on a Î T, one for each terminal.

Transitions simulate left-most derivation S Þ SS Þ (S)S Þ ((S))S Þ (())S Þ (())(S) Þ (())() (q, "(())()" ,S ) |- [1] (q, "(())()" ,SS ) |- [2] (q, "(())()" ,(S)S ) |- [4] (q, "())()" ,S)S ) |- [4] (q, "())()" ,(S))S ) |- [4] (q, "))()" ,S))S ) |- [3] (q, "))()" ,))S ) |- [5] (q, ")()" ,)S ) |- [5] (q, "()" ,S ) |- [2] (q, "()" ,(S) ) |- [4] (q, ")" ,S) ) |- [3] (q, ")" ,) ) |- [5] (q, e ,e ) d(q, L,S) = (q, SS) S ® SS d(q, L,S) = (q, (S) ) S ® (S) d(q, L,S) = (q, L ) S ® L d(q, (, ( ) = (q,L) d(q, ), ) ) = (q,L) Note there is an entry in d for each terminal and non-terminal symbol. The stack operations mimic a top down parse, replacing Non-terminals with the rhs of a production.

Proof Outline To prove that every string of L(G) is accepted by the PDA M, prove the following more general fact: If S Þleft-most* a then (q,uv,S) |-* (q,v,b) where a = ub is the “leftmost factorization” of a (u is the longest prefix of a that belongs to T*, i.e. all terminals). For example: if a = abcWdXa then u = abc, and b = WdXa, since the next symbol after abc is WÎV (a non-terminal or L) S Þlm* abcW… then (q, abcV,S) |-* (q,V, W…) The proof is by induction on the length of the derivation of a.

If (q,w,A) |-* (q, L, L), then A Þ* w We also need to prove that every string accepted by M belongs to L(G). Again, to make induction work, we need to prove a slightly more general fact: If (q,w,A) |-* (q, L, L), then A Þ* w For all Stacks A, letting A = Start we have our proof. This time we induct on the length of execution of M that leads from the ID (q,w,A) to (q, L , L).

A Grammar from a PDA Assume the M = (Q,S,G,d,q0,Z0) is given, and that it accepts by empty stack. Consider execution of M on an accepted input string. If at some point of the execution of M the stack is Z (Z is on top, z is the rest of stack) In terms of instantaneous descriptions (statei, input, Z) |- . . . Then we know that eventually the stack will be z. Why? Because we assume the input is accepted, and M accepts by empty stack, so eventually Z must be removed from the stack

(statei, aX, Z) |-* (statej, X, ) The sequence of moves between these two instants is the “net popping” of Z from the stack. During this sequence of moves, the stack may grow and shrink several times, some input will be consumed (the a), and M will pass through a sequence of states, from statei to statej.

Net Popping Net popping is fundamental for the construction of a CFG G equivalent to M. We will have a variable (Non-terminal) [qZp] in the CFG G for every triple in (q,Z,p) Î Q×G×Q from the PDA. Recall Q is the set of states G Is the set of stack symbols We want the rhs of a production whose lhs is [qZp] to generate precisely those strings w Î S* such that M can move from q to p while reading the input w and doing the net popping of Z. A production like [qZp] -> ? This can be also expressed as (q,w,Z) |-* (p, L , L) Productions of G correspond to transitions of M.

If (p,z) Î d(q,a,Z), then there is one or more corresponding productions, depending on complexity of z. If z = L, we have [qZp] ® a If z = Y, we have [qZr] ® a[pYr] for every state r If z = YY’ we have [qZs] ® a[pYr][rY's], for every pair of states r and s. You can guess the rule for longer z.

Example 0X0 -> a 0X0 0X1 -> a 0X1 1X1 -> b 0X1 -> L Q = {0,1} S = {a,b} = {X} d(0,a,X) = { (0,X) } d (0,L,X) = { (1,L) } d (1,b,X) = { (1,L) } Q0 = 0 Z0 = X F = {}, accepts by empty stack Non-terminals (q,Z,p) Î Q×G×Q (0,'X',0) (0,'X',1) (1,'X',0) (1,'X',1) 0X0 -> a 0X0 0X1 -> a 0X1 1X1 -> b 0X1 -> L Productions, At least one from each element in delta (p,z) Î d(q,a,Z) (0,a,X,0,X) (1,b,X,1,L) (0,L,X,1,L)]