Chapter 7 PDA and CFLs.

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.
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 Part II: PDAs and CFG Chapter 12.
PDAs => CFGs Sipser 2.2 (pages ). Last time…
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
CFG => PDA Sipser 2 (pages ). CS 311 Fall Formally… A pushdown automaton is a sextuple M = (Q, Σ, Γ, δ, q 0, F), where – Q is a finite set.
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.
Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
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.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
1 Converting NPDAs to Context-Free Grammars. 2 For any NPDA we will construct a context-free grammar with.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Pushdown Automaton (PDA)
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.
Chapter 9 Turing Machine (TMs).
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Pushdown Automata.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
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.
Push-down Automata Section 3.3 Fri, Oct 21, 2005.
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.
Chapter 6 Properties of Regular Languages. 2 Regular Sets and Languages  Claim(1). The family of languages accepted by FSAs consists of precisely the.
Pushdown Accepters & Context-Free Grammars Sipser, Theorem 2.12 Denning, Chapter 8.
Chapter 7 Pushdown Automata
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages.
C SC 473 Automata, Grammars & Languages Automata, Grammars and Languages Discourse 04 Context-Free Grammars and Pushdown Automata.
Formal Languages, Automata and Models of Computation
1 Chapter 6 Pushdown automata Sagrada Familia ( 聖家 堂 ), Barcelona, Spain.
1 Alphabets: An Alphabet is a finite set of symbols. We will usually use  to denote the alphabet of input symbols or “terminal characters.” String: A.
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.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
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 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
CS6800 Advance Theory of Computation Spring 2016 Nasser Alsaedi
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Pushdown Automata - like NFA-  but also has a stack - transition takes the current state, the current input symbol, and the top-of-the-stack symbol (which.
Recap: Nondeterministic Finite Automaton (NFA) A deterministic finite automaton (NFA) is a 5-tuple (Q, , ,s,F) where: Q is a finite set of elements called.
CSE 105 theory of computation
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
Pushdown Automata Reading: Chapter 6.
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

Chapter 7 PDA and CFLs

7.1 PDA Is an enhanced FSA with an internal memory system, i.e., a (pushdown) stack. Overcomes the memory limitations and increases the processing power of FSAs. Defn. 7.1.1 A pushdown automaton (PDA) is a sextuple (Q, , , , q0, F), where Q is a finite set of states  is a finite set of input symbols, called input alphabet  is a finite set of stack symbols, called stack alphabet q0  Q, is the start state F  Q, is the set of final states : Q  (  {  })  (  {  })  Q  (  {  }), a (partial) transition function

7.1 PDA A convention: Stack symbols are capital letters Greek letters represent strings of stack symbols An empty stack is denoted  A represents a stack with A as the top element

7.1 PDA  is of the form (qi0, a, A0) = { [qi1, A1], [qi2, A2], ..., [qin, An] } where the transition [qij, Aj]  (qi0, a, A0), 1  j  n denotes that qi0 is the current state a is the current input symbol A0 is the current top of the stack symbol qij (1  j  n) is the new state, and Aj is the new top of the stack symbol and in a state (transition) diagram, it is denoted qi0 qij a A0/Aj

7.1 Pushdown Automaton Input Tape state indicator s0 s3 s4 s1 · state indicator s0 s3 s4 s1 Tape Head Head moves in this direction Control Mechanism Stack s5 s2

7.1 PDA Special cases (note that qi and qj can be the same): [qj, A]  (qi, a, ) [qj, ]  (qi, , A) [qj, A]  (qi, , ) [qj, ]  (qi, a, ) The PDA notation [qi, w, ] [qj, v, ] indicates that [qj, v, ] can be obtained from [qi, w, ] as a result of a sequence of transitions (i.e., 0 or more). Example. The PDA M = (Q, , , , q0, F), where  is Accepts anbn (n  0) with an empty stack and in an accepting state /* Consume the input, push a stack symbol */ /* Consume no input, pop the TOS symbol */ /* Consume no input, push a stack symbol */ /* Consume input, no push/pop, an FSA transition */ * m

7.1 PDA Defn. 7.1.2 Let M = (Q, , , , q0, F) be a PDA. A string w  * is accepted by M if  [q0, w, ] [qi, , ], where qi  F. L(M), the language of M, is the set of strings accepted by M. Example (7.1.1) Give a PDA that accepts the language { wcwR | w  { a, b }* }. Defn. A PDA is deterministic if there is at most one transition that is applicable for each configuration of <state, input symbol, stack top symbol>. Example 7.1.2 Construct L = { ai | i  0 }  { ai bi | i  0 } Example 7.1.3 Construct all even-length palindromes over { a, b } Nondeterministic PDAs allow the machines to “guess” For some NPDAs, their counterparts (i.e., DPDAs) do not exist Languages L accepted by DPDA include RL, and L  CFL *

7.2 Variations on PDAs Defn. A PDA is atomic if each transition in the PDA is of one of the following forms: [qj, ]  (qi, a, ) [qj, ]  (qi, , A) [qj, A]  (qi, , ) Theorem 7.2.1. Let M be a PDA. Then  an atomic PDA M’ such that L(M’) = L(M). Replace each non-atomic transition by a sequence of atomic transitions Defn. A transition [qj, ]  (qi, a, A), where   + is called extended transition. A PDA containing extended transition is called an extended PDA. Example 7.2.1. Construct L = { aib2i | i  1 }, with PDA, atomic PDA, and extended PDA : process an input symbol : pop the stack : push a stack symbol

7.2 Variations on PDAs

PDA Defn. A string w is accepted by final state if  a computation [q0, w, ] [qi, , ], where qi  F and   *, i.e., the content of the stack is irrelevant. Lemma 7.2.3. Let L be a language accepted by a PDA M with acceptance defined by final state. Then  a PDA M’ that accepts L by final state and empty stack. Proof. Let M’ = (Q  {qf }, , , ’, q0, {qf }), where M = (Q, , , , q0, F), ’  , qi  F, ’(qi, , ) = { [qf, ] }, and A  , ’(qf, , A) = { [qf, ] } hence, given M, [q0, w, ] [qi, , ] * M * M’ * [qf, , ] [qf, , ]. M’

PDA Defn. A string w is said to be accepted by empty stack if  a computation [q0, w, ] [qi, , ], where qi may not be a final state. Lemma 7.2.4. Let L be a language accepted by a PDA M with acceptance defined by empty stack. Then  a PDA M’ that accepts L by final state and empty stack. Proof. (P. 230) Let M’ = (Q  {q0’}, , , ’, q0’, Q), where M = (Q, , , , q0), and each state in M’ is a final state, except q0’, the new start state, where ’(q0’, a, A) = (q0, a, A), and qi  Q, a    {  }, A    {  }, ’(qi, a, A) = (qi, a, A) +

Two-Stack PDAs Two-stack PDAs, an extension of PDAs A two-stack PDA (2PDA) is a sextuple (Q, , , , q0, F), where Q, , , q0, and F are the same as in a one-stack PDA : Q  (  {  })  (  {  })  (  {  })  Q  (  {  })  (  {  }) 2PDAs accept non-CFLs, in addition to all CFLs Accepting criteria: Consume an input string Enter a final state Empty both stacks

Two-Stack PDAs Example. Given L = { aibici | i  0 }, L is not a CFL. A 2PDA M that accepts L is q0 >  / / q2 q1 a /A / c / A/ b A/ /A [q0, aabbcc, , ] |- [q0, abbcc, A, ] |- [q0, bbcc, AA, ] |- [q1, bcc, A, A] |- [q1, cc, , AA] |- [q2, c, , A] |- [q2, , , ]

Two-Stack PDAs Example. A 2PDA M accepts L = { aibicidi | i  0 } > q0 >  / / q3 q2 a /A / d C/ / b A/ /B q1 c /C B/ [q0, aabbccdd, , ] |- [q0, abbccdd, A, ] |- [q0, bbccdd, AA, ] |- [q1, bccdd, A, B] |- [q1, ccdd, , BB] |- [q2, cdd, C, B] |- [q2, dd, CC, ] |- [q3, d, C, ] |- [q3, , , ]

7.3 PDA and CFLs Defn. 5.6.1. A CFG G = (V, , P, S) is in Greibach normal form (GNF) if each rule has one of the following forms: i) A  aA1A2 ... An ii) A  a iii) S   where a   and Ai  V - { S }, i = 1, 2, ..., n Example: Given the language L = { aibjck | i, j, k  0 and (i = j or i = k) }, the following PDA accepts L: i = j i = k

7.3 PDA and CFLs The CFG G that generates the set of string in the language L = { aibjck | i, j, k  0 and (i = j or i = k) }, i.e., L(G), is S  aAc | aDbC |  | B | C A  aAc | bB |  B  bB |  D  aDb |  C  cC |  i = k i = j

7.3 PDA and CFLs Theorem 7.3.1 Let L be a CFL. Then  a PDA that accepts L. Proof. Let G = (V, , P, S) be a grammar in GNF that generates L. An extended PDA M with start state q0 is defined by Qm = { q0, q1 }, m = , m = V - { S }, and Fm = { q1 } with transitions (a) (q0, a, ) = { [q1 , w] | S  aw  P } (b) (q1, a, A) = { [q1 , w] | A  aw  P and A  V - { S }} (c) (q0, , ) = { [q1 , ] | S    P }

7.3 PDA and CFLs Proof. We must show that i) L  L(M) For each derivation S uw with u  + and w  V*, we show that  a computation [q0, u, ] [q1, , w] in M by induction on the length of the derivation, i.e., n. Basis: n = 1, i.e., S  aw, where a   and w  V* The transition (a), i.e., (q0, a, ) = { [q1 , w] | S  aw  P }, yields the desired computation. Induction Hypothesis: Assume for every derivation S uw,  a computation [q0, u, ] [q1, , w] in M. * Þ *

PDA and CFLs Induction: * * Now consider S uw. Let u = va  + & w  V*, S uw can be written as S vAw2  uw, where w = w1w2 & A  aw1  P. By I.H. & [q1, w1]  (q1, a, A) of Transition (b), i.e., (q1, a, A) = { [q1 , w] | A  aw  P & A  V - { S } } [q0, va, ] [q1, a, Aw2] [q1, , w1w2] If   L, then S    P yields the Transition (c), i.e., [q0, , ] [q1, ] ii) L(M)  L Show that for every computation [q0, u, ] [q1, , w],  a derivation S uw in G by induction. n+1 Þ n+1 Þ n Þ * * * Þ

PDA and CFLs Every language accepted by a PDA is context-free The Transformation Algorithm: Let M = (Q, , , , q0, F) be a PDA. We construct the grammar G .. L(G) = L(M). (i) Construct an extended PDA M’ w/ ’ as its transition function from M .. (a) Given [qj, ]  (qi, u, ), construct [qj, A]  ’(qi, u, A), A   (b) Given [qj, B]  (qi, u, ), construct [qj, BA]  ’(qi, u, A), A   (ii) Given the PDA M’ as constructed in step (i), construct G = (V, , P, S), where V = { S }  { <qi, A, qj> | qi, qj  Q, A    {  } }. <qi, A, qj> denotes a computation that begins in qi, ends in qj & removes A ( ) from the stack.

The Transformation Algorithm P is constructed as follows: 1. S  <q0, , qj>, qj  F 2. For each transition [qj, B]  (qi, X, A), where A    {}, create {<qi, A, qk>  X<qj, B, qk> | qk  Q} 3. For each transition [qj, BA]  (qi, X, A), where A  , create {<qi, A, qk>  X<qj, B, qn><qn, A, qk>| qk, qn  Q} 4. For each qk  Q, create <qk, , qk>  . Rule 1: A computation begins w/ the start state, ends in a final state, & terminate w/ an empty stack, i.e., a successful computation in M’ Rules 2 & 3: Trace the transitions of M’ Rule 4: Terminate derivations

PDA & CFLs Example 7.3.1. Given the PDA M such that L(M) = { ancbn | n  0 }. The corresponding CFG G is given in Table 7.3.1 (on P.240). M is Q = {q0, q1} (q0, a, ) = {[q0, A]}  = {a, b, c} (q0, c, ) = {[q1, ]}  = {A} (q1, b, A) = {[q1, ]} F = {q1} M’ is M with the additional transitions: (q0, a, A) = { [q0, AA] } and (q0, c, A) = { [q1, A] }

PDA and CFLs Example 7.3.1 P in G includes: using Rule 1: S  < q0, , q1 > given (q0, a, ) = { [q0, A] } & Rule 2: <q0, , q0>  a <q0, A, q0> <q0, , q1>  a <q0, A, q1> given (q0, a, A) = {[q0, AA]} & Rule 3: <q0, A, q0>  a <q0, A, q0> <q0, A, q0 > <q0, A, q0>  a <q0, A, q1> <q1, A, q0 > <q0, A, q1>  a <q0, A, q0> <q0, A, q1 > <q0, A, q1>  a <q0, A, q1> <q1, A, q1 > given (q0, c, ) = { [q1,  ] } & Rule 2: <q0, , q0>  c <q1, , q0> <q0, , q1>  c <q1, , q1> given (q0, c, A) = { [q1, A] } & Rule 2: <q0, A, q0>  c <q1, A, q0> <q0, A, q1>  c <q1, A, q1> given (q1, b, A) = { [q1, ] } <q1, A, q0>  b <q1, , q0> <q1, A, q1>  b <q1, , q1> using Rule 4: <q0, , q0>   <q1, , q1>  