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.

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,
Context Free Grammars.
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.
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.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Pushdown Automaton (PDA)
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
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.
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
Finite State Machines Data Structures and Algorithms for Information Processing 1.
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 (PDA) Part 2 While I am distributing graded exams: Design a PDA to accept L = { a m b n : m  n; m, n > 0} MA/CSSE 474 Theory of Computation.
Chapter 7 PDA and CFLs.
1 Section 14.2 A Hierarchy of Languages Context-Sensitive Languages A context-sensitive grammar has productions of the form xAz  xyz, where A is a nonterminal.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Design contex-free grammars that generate: L 1 = { u v : u ∈ {a,b}*, v ∈ {a, c}*, and |u| ≤ |v| ≤ 3 |u| }. L 2 = { a p b q c p a r b 2r : p, q, r ≥ 0 }
Lecture # 28 Theory Of Automata By Dr. MM Alam 1.
1 Section 12.3 Context-Free Parsing We know (via a theorem) that the context-free languages are exactly those languages that are accepted by PDAs. When.
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.
Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein.
1 1. Let A ={r, p, i } and B = { w, o, r, l, d }. What does each of the following (a), (b) and (c) denote? Briefly explain in plain English. (a) A * B.
Chapter 7 Pushdown Automata
Lecture # 26 Theory Of Automata By Dr. MM Alam 1.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
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.
Formal Languages, Automata and Models of Computation
1 Section 13.1 Turing Machines A Turing machine (TM) is a simple computer that has an infinite amount of storage in the form of cells on an infinite tape.
1 Turing Machines and Equivalent Models Section 13.1 Turing Machines.
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.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
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 Section 11.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
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.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
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.
Formal Languages, Automata and Models of Computation
CSE 105 theory of computation
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
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,
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
REGULAR LANGUAGES AND REGULAR GRAMMARS
Intro to Data Structures
CSE 105 theory of computation
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
… NPDAs continued.
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Recap lecture 37 New format for FAs, input TAPE, START, ACCEPT , REJECT, READ states Examples of New Format of FAs, PUSHDOWN STACK , PUSH and POP states,
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSE 105 theory of computation
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSE 105 theory of computation
Presentation transcript:

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 start with one designated symbol on the stack. A state transition depends on the input symbol and the top of the stack. The machine then performs a stack operation and enters the next state. Representation can be graphical or with sets of 5-tuples. For example: ij or (i, b, C, pop, j) Execution: If the machine is in state i and the input letter is b and C is on top of the stack, then pop the stack and enter state j. Nondeterminism can occur in two ways, as in the following examples. i j k i j k Acceptance: A string w is accepted by a PDA if there is a path from the start state to a final state such that the input symbols on the path edges concatenate to w. Otherwise, w is rejected.

2 Example. A PDA to accept the language {a n b n | n > 0} as a graph and as a set of 5-tuples. 0 Start X 1 2 (0, a, X, push(a), 0) (0, a, a, push(a), 0) (0, b, a, pop, 1) (1, b, a, pop, 1) (1, , X, nop, 2). Quiz. How would you modify the machine to accept {a n b n | n  N}? Answer: Add the instruction (0, , X, nop, 2). Example/Quiz. Find a PDA to accept the language {a 2n b n | n  N}. 0 Start X 12 3 ID for input aaaabb: (0, aaaabb, X) (0, aaabb, aX) (0, aabb, aaX) (0, abb, aaaX) (0, bb, aaaaX) (1, b, aaaX) (2, b, aaX) (1, , aX) (2, , X) (3, , X). A solution:

3 Empty-Stack Acceptance. A PDA can also be defined to accept a string by the condition that the stack is empty. The two types of acceptance are equivalent in that they both define PDAs that accept the same class of languages. Transform final-state acceptance to empty-stack acceptance: Introduce a new start state s, a new start symbol Y, a new empty state e, and construct edges and actions as shown in the diagram below. Note that ? stands for any stack symbol. Start X s Y e final-state PDA Quiz: If the final-state PDA is deterministic, the transformed empty-stack PDA could be nondeterministic. Why? Answer: If the final-state PDA has an edge emitted from a final state, then the empty-stack PDA constructs a nondeterministic choice from that final state. For example, a final-state PDA for {ab n c n | n  N} could have a final state k to accept the string a that also emits an edge to take care of any string ab n + 1 c n + 1. The empty-stack PDA would construct a nondeterministic choice from k by adding instructions of the form (k, , ?, pop, e).

4 Transform empty-stack acceptance to final-state acceptance: Introduce a new start state s, a new start symbol Y, a new final state ƒ, and construct edges and actions as shown in the diagram below. Quiz: If the empty-stack PDA is deterministic, then the transformed final-state PDA is also deterministic. Why? Answer: Because the instructions of the empty-stack PDA do not use stack symbol Y. So the only time a new instruction can be executed is when Y is on top of the stack, meaning that the empty-stack PDA has emptied it’s original stack and can’t move. Theorem: The context-free languages are exactly the languages accepted by PDAs. Proof: We’ll see two algorithms, one to transform a C-F grammar into an empty-stack PDA, and one to transform an empty-stack PDA into a C-F grammar. QED. Start X s Y empty-stack PDA ƒ

5 Transform a C-F grammar to empty-stack PDA The idea is to construct a PDA whose execution corresponds to a leftmost derivation. The PDA has one state, but we allow multiple stack operations. The stack symbols are the terminals and nonterminals of the grammar. The designated starting stack symbol is the grammar start symbol. We’ll illustrate the algorithm with an example. Example. A leftmost derivation of abbcb: S  aSb  aBCb  abBCb  abbCb  abbcCb  abbcb. (0, abbcb, S) (0, abbcb, aSb) (0, bbcb, Sb) (0, bbcb, BCb) (0, bbcb, bBCb) (0, bcb, BCb) (0, bcb, bCb) (0, cb, Cb) (0, cb, cCb) (0, b, Cb) (0, b, b) (0, ,  ). Example. ID for input string abbcb: TerminalsCorresponding PDA Instructions a(0, a, a, pop, 0) b(0, b, b, pop, 0) c(0, c, c, pop, 0) Productions S  aSb(0, , S,  pop, push(b), push(S), push(a) , 0) S  BC(0, , S,  pop, push(C), push(B) , 0) B  bB(0, , B,  pop, push(B), push(b) , 0) B  b(0, , B,  pop, push(b) , 0) C  cC(0, , C,  pop, push(C), push(c) , 0) C   (0, , C, pop, 0) Grammar S  aSb | BC B  bB | b C  cC | .

6 Transform an empty-stack PDA to a C-F grammar The idea is to construct a grammar whose leftmost derivations correspond to computation sequences. For each stack symbol B and each pair of states i and j construct a nonterminal B ij from which a leftmost derivation will correspond to a computation sequence that starts in state i with B on the stack and ends in state j with B popped from the stack. i j B ij  a B ik  aB jk for each state k. B il  aC jk B kl for each state k and l. S  X sj for each state j. (S is start symbol) ij k ij kl s X Start j Corresponding Grammar ProductionsPDA Instruction (For the following instructions, the dotted lines represent possible paths to states that pop the desired stack symbol.)

7 Example/Quiz. Use the algorithm to transform the following empty-stack PDA into a C-F grammar. Start 0 X 1 Quiz: Simplify the preceding grammar by deleting productions that do not derive terminal strings and productions that are not reachable from the start symbol. Solution: The start state 0 with X on the stack gives: S  X 00 | X 01 The pop operation (1, a, X, pop, 1) gives: X 11  a The pop operation (1, a, A, pop, 1) gives: A 11  a The push operation (0, a, X, push(A), 0) gives: X 00  aA 00 X 00 | aA 01 X 10 X 01  aA 00 X 01 | aA 01 X 11 The nop operation (0, a, A, nop, 1) gives: A 00  aA 10 A 01  aA 11 Solution:S  X 01 X 01  aA 01 X 11 A 01  aA 11 X 11  a A 11  a or, S  aaaa.

8 Example. We’ll try to find a grammar for the language L = {w  {a, b}* | n a (w) = n b (w)} by constructing an empty-stack PDA to accept L and then transforming it into a C-F grammar. Consider the following single-state empty-stack PDA. Start 0 X Idea of Proof: Assume, WLOG, that the input string begins with a. Then A is pushed and this action continues for each consecutive a. When the first b occurs, A is popped, which means that an a-b pair has been counted. The only way to get back to X on top is if the string has an equal number of a’s and b’s so far. If the input is exhausted, then pop X and accept the string. Otherwise, the process continues as described. PDA Transformed into C-F grammar: S  X 00 X 00   | aA 00 X 00 | bB 00 X 00 A 00  b | aA 00 A 00 B 00  a | bB 00 B 00. A Simplified C-F grammar: S   | aAS | bBS A  b | aAA B  a | bBB. Example Derivation of aababb: S  aAS  aaAAS  aabAS  aabaAAS  aababAS  aababbS  aababb.

9 Nondeterministic PDAs are more powerful than deterministic PDAs. An example is to consider the language of even palindromes over {a, b}. A context-free grammar for the language is given by S   | aSa | bSb Any PDA to accept the language must make a nondeterministic decision to start comparing the second half of a string with the reverse of the first half. Quiz: Transform the grammar into a PDA A Solution (using the algorithm) (0, a, a, pop, 0) (0, b, b, pop, 0) (0, , S, pop, 0) (0, , S,  pop, push(a), push(S), push(a) , 0) (0, , S,  pop, push(b), push(S), push(b) , 0).