CS 154 Formal Languages and Computability March 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.

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 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.
CS21 Decidability and Tractability
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 Module 32 Pushdown Automata (PDA’s) –definition –Example We define configurations and computations of PDA’s We define L(M) for PDA’s.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.

Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Prof. Busch - LSU1 Pushdown Automata PDAs. Prof. Busch - LSU2 Pushdown Automaton -- PDA Input String Stack States.
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
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.
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)
Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
Pushdown Automata Part I: PDAs Chapter Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2)
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.
Chapter 7 Pushdown Automata
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.
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.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Formal Languages, Automata and Models of Computation
CS 154 Formal Languages and Computability February 4 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CS 154 Formal Languages and Computability February 9 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
1.Draw a parse tree for the following derivation: S  C A C  C A b b  b b A b b  b b B b b  b b a A a a b b  b b a b a a b b 2. Show on your parse.
1.Draw a parse tree for the following derivation: S  C A C  C A b b  b b A b b  b b B b b  b b a A a a b b  b b a b a a b b 2. Show on your parse.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
CS 154 Formal Languages and Computability March 8 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
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.
CS 154 Formal Languages and Computability April 28 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability March 22 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
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.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Formal Languages, Automata and Models of Computation
Theory of Computation Pushdown Automata pda Lecture #10.
Pushdown Automata (PDA). Part 2
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
AUTOMATA THEORY VI.
Pushdown Automata (PDA). Part 3
… NPDAs continued.
Pushdown automata The Chinese University of Hong Kong Fall 2011
More About Nondeterminism
Presentation transcript:

CS 154 Formal Languages and Computability March 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak Pushdown Automata  The machine class of pushdown automata (PDA) includes a stack for storage: 2 Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak Pushdown Automata, cont’d  Nondeterministic pushdown automata (NPDA) accepts exactly the family of context-free languages.  Deterministic pushdown automata (DPDA) are not equivalent to the nondeterministic ones. DPDA recognize a new family of deterministic context-free languages. Which are a proper subset of the context-free languages. 3

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak How a Pushdown Automaton Works  Whenever a PDA reads the current input symbol, depending on … the symbol it just read the state of the control unit the symbol on top of the stack  … the PDA makes a move by transitioning to a new state pushing or popping a symbol  A PDA can make a move without reading a symbol ( λ -transition). 4

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak How to Program a Pushdown Automaton  We can draw a flowchart to represent a program for a PDA.  The flowchart requires: A single start state. A single halt-and-accept state. Stack push operation for a single symbol. Read-and-decide operation to read a single symbol from the input and decide what to do next. Pop-and-decide operation to pop a single symbol from the stack and decide what to do next. 5

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak How to Program a Pushdown Automaton, cont’d  Assumptions: The stack initially contains the stack start symbol. λ represents the end of the input string. There is no reject state. If the PDA cannot continue based on the current input symbol or the symbol at the top of the stack, it halts and rejects the input. 6

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak Program 1: S  ( S ) | SS | λ  Initialize the stack with the stack start symbol 0.  Accept balanced parentheses, such as (())()  Push a 1 each time you read a (  Pop a 1 each time you read a ) 7 Start Read Push 1 Pop Accept λ ( 1 ) 0 Use the stack to ensure there’s a ) for every (.

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak Program 2: 8 a Start Read Push 1 PopReadPop Accept Read a ab 1 λ b 0 λ  Initialize the stack with the stack start symbol 0.  Push a 1 each time you read an a.  Switch modes upon reading the first b.  Pop a 1 each time you read a b. Use the stack to keep track of how many a ’s were read.

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak  Initialize the stack with the stack start symbol z.  Stack the symbols of w as they’re read. They will be popped in reverse order.  Pop the stacked symbols while reading the symbols of w R and make sure the current input symbol matches the latest popped symbol.  But where does w end and w R begin? 9 Program 3:

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak Program 3: cont’d 10 Start Read Push a Push b ab Pop Accept ReadPop ab ab z λ Nondeterminism to the rescue!

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak  where Q is a finite set of internal states of the control unit Σ is the input alphabet Γ is the stack alphabet, a finite set of symbols set of finite subsets of is the transition function is the initial state of the control unit is the stack start symbol is the set of final states 11 Definition of a Nondeterministic PDA (NPDA)

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak set of finite subsets of The NPDA Transition Function δ  The transition function δ has three arguments: the current state the current input symbol (can be λ to not consume) the current symbol on top of the stack  The result is a set of pairs (q, x) where q is the next state and x is a string to push onto the stack in place of the current top of stack symbol. Push the symbols of string x one at a time starting at the right end of the string. 12 Set of pairs because an NPDA is nondeterministic. No move is possible if the stack is empty.

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak NPDA for 13 Q = {q 0, q 1, q 2, q 3 } Σ = {a, b}  = {0, 1} stack start symbol = 0 F = {q 3 } δ(q 0, a, 0) = { (q 1, 10), (q 3, ) } δ(q 0,, 0) = { (q 3, ) } δ(q 1, a, 1) = { (q 1, 11) } δ(q 1, b, 1) = { (q 2, ) } δ(q 2, b, 1) = { (q 2, ) } δ(q 2,, 0) = { (q 3, ) } Start Read Push 1 PopReadPop Accept a Read a ab 1 λ b 0 Pop 0 λ 1.current input symbol 2.current top-of-stack symbol 3.top-of-stack replacement q0q0 q1q1 q3q3 q2q2 Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak NPDA for 14 Start Rea d Push a Push b ab Pop Accept Rea d Pop a b ab z λ Q = {q 0, q 1, q 2 } Σ = {a, b}  = {a, b, z} stack start symbol = z F = {q 2 }  Push w onto the stack:  Guess the string middle:  Match input w R vs. stack:  Successful match: δ(q 0, a, a) = { (q 0, aa) } δ(q 0, b, a) = { (q 0, ba) } δ(q 0, a, b) = { (q 0, ab) } δ(q 0, b, b) = { (q 0, bb) } δ(q 0, a, z) = { (q 0, az) } δ(q 0, b, z) = { (q 0, bz) } δ(q 0,, a) = { (q 1, a) } δ(q 0,, b) = { (q 1, b) } δ(q 1, a, a) = { (q 1, ) } δ(q 1, b, b) = { (q 1, ) } δ(q 1,, z) = { (q 2, z) } q0q0 q2q2 q1q1 Guess!

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak Instantaneous Description of a PDA  At any time, the relevant factors of a PDA are represented by the triplet (q, w, u) : q the current state of the control unit w the unread part of the input string u the current contents of the stack (the leftmost symbol is the top of stack)  Use the symbol to denote a move: if and only if 15 (q 1, aw, bx) (q 2, w, yx)

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak 16 NPDA for cont’d  Push w onto the stack:  Guess the string middle:  Match input w R vs. stack:  Successful match: δ(q 0, a, a) = { (q 0, aa) } δ(q 0, b, a) = { (q 0, ba) } δ(q 0, a, b) = { (q 0, ab) } δ(q 0, b, b) = { (q 0, bb) } δ(q 0, a, z) = { (q 0, az) } δ(q 0, b, a) = { (q 0, bz) } δ(q 0,, a) = { (q 1, a) } δ(q 0,, b) = { (q 1, b) } δ(q 1, a, a) = { (q 1, ) } δ(q 1, b, b) = { (q 1, ) } δ(q 1,, z) = { (q 2, z) } (q 0, abba, z) (q 0, bba, az) (q 0, ba, baz) (q 1, ba, baz) (q 1, a, az) (q 1,, z) ) (q 2,, z) Moves to accept the string abba :The correct guess that uses δ(q 0,, b) = { (q 1, b) } An incorrect guess (q 0, ba, baz) (q 0, a, bbaz) that uses δ(q 0, b, b) = { (q 0, bb) }

Computer Science Dept. Spring 2016: March 10 CS 154: Formal Languages and Computability © R. Mak Context-Free Languages and NPDAs  For any context-free language L, there exists an NPDA M such that L = L(M).  If L = L(M) for some NPDA M, then L is a context-free language. 17