1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages.

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
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.
CFGs and PDAs Sipser 2 (pages ). Long long ago…
Finite Automata Section 1.1 CSC 4170 Theory of Computation.
CS21 Decidability and Tractability
CFGs and PDAs Sipser 2 (pages ). Last time…
CFG => PDA Sipser 2 (pages ).
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.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
Costas Busch - RPI1 NPDAs Accept 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.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Pushdown Automaton (PDA)
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Pushdown Automata.
Chapter 7 PDA and CFLs.
1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s Pushdown Automata 11.
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.
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
Chapter 7 Pushdown Automata
Chapter 7 Pushdown Automata. Context Free Languages A context-free grammar is a simple recursive way of specifying grammar rules by which strings of a.
PushDown Automata. What is a stack? A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack.
Three Basic Concepts Languages Grammars Automata.
Chapter 5 Context-Free Languages Regular language are effective in describing certain simple patterns. But it is not enough to describe programming languages.
Formal Languages, Automata and Models of Computation
98 Nondeterministic Automata vs Deterministic Automata We learned that NFA is a convenient model for showing the relationships among regular grammars,
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
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 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
1 Finite Automata. 2 Introductory Example An automaton that accepts all legal Pascal identifiers: Letter Digit Letter or Digit "yes" "no" 2.
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.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Formal Languages, Automata and Models of Computation
Introduction to Formal Languages and Automata
Theory of Computation Pushdown Automata pda Lecture #10.
NPDAs Accept Context-Free Languages
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
Pushdown Automata Reading: Chapter 6.
Chapter 5 Pushdown Automata
Chapter 7 Regular Grammars
… NPDAs continued.
More About Nondeterminism
Non Deterministic Automata
Presentation transcript:

1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages.

2 Pushdown Automata {a, b}* is regular. {a k b k | k is a constant} is regular. {a n b n | n  0} is not regular.

3 Finite Automata Control unit q 0 Input file yes/no

4 Pushdown Automata Control unit q 0 Input file yes/no Stack

5 Non-deterministic Pushdown Automata (NPDA) M = (Q, , , , q 0, z, F) Q: finite set of internal states  : finite set of symbols - input alphabet  : finite set of symbols - stack alphabet  : Q  (  { })    finite subsets of Q   * transition function q 0  Q: initial state z   : stack start symbol F  Q: set of final states

6 Non-deterministic Pushdown Automata (NPDA)  : Q  (  { })    finite subsets of Q   * stack topstack top replacement

7 Example  (q 1, a, b) = {(q 2, cd), (q 3, )} b d c q1q1 q2q2 q3q3

8 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2, q 3 }  (q 0, a, 0) = {(q 1, 10), (q 3, )}  = {a, b}  (q 0,, 0) = {(q 3, )}  = {0, 1}  (q 1, a, 1) = {(q 1, 11)} z = 0  (q 1, b, 1) = {(q 2, )} F = {q 3 }  (q 2, b, 1) = {(q 2, )}  (q 2,, 0) = {(q 3, )}

9 Instantaneous Description (q, w, u) current stateunread part ofstack contents input string

10 Instantaneous Description move: (q 1, aw, bx)  (q 2, w, yx) iff (q 2, y)   (q 1, a, b)

11 Instantaneous Description (q 1, x, y)     (q 2, u, v) (q 1, x, y)     (q 2, u, v)

12 Language accepted by NPDA Let M = (Q, , , , q 0, z, F) be an NPDA. L(M) = {w   * | (q 0, w, z)     (q f,, u), q f  F, u   * }

13 Example L = { w  {a, b} * | n a (w) = n b (w) } M = (Q, , , , q 0, z, F) ?

14 Example L = { w  {a, b} * | n a (w) = n b (w) } M = (Q, , , , q 0, z, F) Q = {q 0, q f }  (q 0,, z) = {(q f, z)}  = {a, b}  (q 0, a, z) = {(q 0, 0z)}  = {0, 1, z}  (q 0, b, z) = {(q 0, 1z)} F = {q f }  (q 0, a, 0) = {(q 0, 00)}  (q 0, b, 0) = {(q 0, )}  (q 0, a, 1) = {(q 0, )}  (q 0, b, 1) = {(q 0, 11)}

15 Example L = { ww R | w  {a, b} + } M = (Q, , , , q 0, z, F) ?

16 Example L = { ww R | w  {a, b} + } M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2 }  = {a, b}  = {a, b, z} F = {q 2 }  (q 0, a, a) = {(q 0, aa)}  (q 0,, a) = {(q 1, a)}  (q 0, b, a) = {(q 0, ba)}  (q 0,, b) = {(q 1, b)}  (q 0, a, b) = {(q 0, ab)}  (q 0, b, b) = {(q 0, bb)}  (q 1, a, a) = {(q 1, )}  (q 0, a, z) = {(q 0, az)}  (q 1, b, b) = {(q 1, )}  (q 0, b, z) = {(q 0, bz)}  (q 1,, z) = {(q 2, z)}

17 NPDA and Context-Free Languages Greibach NF  (q 0,, z) = {(q 1, Sz)} S  aSA | a  (q 1, a, S) = {(q 1, SA), (q 0, )} A  bB  (q 1, b, A) = {(q 1, B)} B  b  (q 1, b, B) = {(q 1, )}  (q 1,, z) = {(q 2, )}

18 Theorem For any context-free language L not containing, there exists an NPDA M such that L = L(M).

19 Theorem Proof: G = (V, T, S, P) M = ({q 0, q 1, q f }, T, V  {z}, , q 0, z, {q f })z  V  (q 0,, z) = {(q 1, Sz)} (q 1, u)   (q 1, a, A) iff A  au  P  (q 1,, z) = {(q f, z)}

20 Example Greibach NF  (q 0,, z) = {(q 1, Sz)} S  aA  (q 1, a, S) = {(q 1, A)} A  aABC | bB | a  (q 1, a, A) = {(q 1, ABC), (q 1, )}  (q 1, b, A) = {(q 1, B)} B  b  (q 1, b, B) = {(q 1, )} C  c  (q 1, c, C) = {(q 1, )}  (q 1,, z) = {(q 2, )}

21 Context-Free Grammars for NPDA M = (Q, , , , q 0, z, F) G = (V, T, S, P) L(G) = L(M)

22 Context-Free Grammars for NPDA M = (Q, , , , q 0, z, F) M^: Single final state Final state entered iff the stack is empty  (q i, a, A) = {c 1, c 2,..., c n } c i = (q j, ) c i = (q j, BC)

23 Context-Free Grammars for NPDA  (q i, a, A) = {(q j, ),... } ?

24 Context-Free Grammars for NPDA  (q i, a, A) = {(q j, ),... } ? At q i erase A and move to q j if receiving a

25 Context-Free Grammars for NPDA  (q i, a, A) = {(q j, BC),... } ?

26 Context-Free Grammars for NPDA  (q i, a, A) = {(q j, BC),... } ? At q i erase A and move to q k if receiving a and at q j erase BC and move to q k

27 Context-Free Grammars for NPDA  (q i, a, A) = {(q j, BC),... } ? At q i erase A and move to q k if receiving a and at q j erase BC and move to q k At q i erase A and move to q k if receiving a and at q j erase B and move to q m and at q m erase C and move to q k

28 Context-Free Grammars for NPDA  (q i, a, A) = {(q j, ),... } At q i erase A and move to q j if receiving a (q i Aq j )  a

29 Context-Free Grammars for NPDA  (q i, a, A) = {(q j, BC),... } At q i erase A and move to q k if receiving a and at q j erase B and move to q m and at q m erase C and move to q k (q i Aq k )  a(q j Bq m )(q m Cq k )

30 Context-Free Grammars for NPDA Start symbol: (q 0 zq f )

31 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2 }  = {a}  = {A, z} F = {q 2 }  (q 0, a, z) = {(q 0, Az)}  (q 0, a, A) = {(q 0, A)}  (q 0, b, A) = {(q 1, )}  (q 1,, z) = {(q 2, )}

32 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2, q 3 }  = {a}  = {A, z} F = {q 2 }  (q 0, a, z) = {(q 0, Az)}  (q 0, a, A) = {(q 0, A)}  (q 0, a, A) = {(q 3, )}  (q 0, b, A) = {(q 1, )}  (q 3,, z) = {(q 3, Az)}  (q 1,, z) = {(q 2, )}  (q 0, b, A) = {(q 1, )}  (q 1,, z) = {(q 2, )}

33 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2, q 3 }  = {a}  = {A, z} F = {q 2 }  (q 0, a, z) = {(q 0, Az)}  (q 0, a, A) = {(q 3, )} (q 0 Aq 3 )  a  (q 3,, z) = {(q 3, Az)}  (q 0, b, A) = {(q 1, )} (q 0 Aq 1 )  b  (q 1,, z) = {(q 2, )} (q 1 zq 2 ) 

34 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2, q 3 }  = {a}  = {A, z} F = {q 2 }  (q 0, a, z) = {(q 0, Az)} (q 0 zq 0 ) ...  (q 0, a, A) = {(q 3, )} (q 0 zq 1 ) ...  (q 3,, z) = {(q 3, Az)} (q 0 zq 2 ) ...  (q 0, b, A) = {(q 1, )} (q 0 zq 3 ) ...  (q 1,, z) = {(q 2, )}

35 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2, q 3 }  = {a}  = {A, z} F = {q 2 }  (q 0, a, z) = {(q 0, Az)} (q 0 zq 0 )  a(q 0 Aq 0 )(q 0 zq 0 ) |  (q 0, a, A) = {(q 3, )} a(q 0 Aq 1 )(q 1 zq 0 ) |  (q 3,, z) = {(q 3, Az)} a(q 0 Aq 2 )(q 2 zq 0 )  (q 0, b, A) = {(q 1, )} a(q 0 Aq 3 )(q 3 zq 0 )  (q 1,, z) = {(q 2, )}...

36 Theorem If L = L(M) for some NPDA M, then L is a context-free language.

37 Theorem Proof: M = (Q, , , , q 0, z, {q f }) G = (V, T, S, P) T =  V = {(q i Aq j ) | A   }S = (q 0 zq f ) P: (q i Aq j )  a iff (q j, )   (q i, a, A) (q i Aq m )  a(q i Bq m )(q m Cq j ) iff (q j, BC)   (q i, a, A)

38 Deterministic Pushdown Automata A DPDA is a pushdown automaton that never has a choice in its move: 1.  (q, a, b) contains at most one element. 2.if  (q,, b) is not empty, then  (q, a, b) must be empty for every a  .

39 Deterministic Context-Free Language A language L is said to be a DCFL iff there exists a DPDA M such that L = L(M).

40 Example M = (Q, , , , q 0, z, F) Q = {q 0, q 1, q 2 }  (q 0, a, 0) = {(q 1, 10)}  = {a, b}  (q 1, a, 1) = {(q 1, 11)}  = {0, 1}  (q 1, b, 1) = {(q 2, )} z = 0  (q 2, b, 1) = {(q 2, )} F = {q 0 }  (q 2,, 0) = {(q 0, )} L = {a n b n | n  0}

41 Homework Exercises: 5, 10, 13 of Section Linz’s book. Exercises: 1, 2, 4, 5, 8, 12 of Section Linz’s book. Exercises: 1, 2, 3, 6, 7 of Section Linz’s book. Presentations: Section 6.3 and Section 7.4.