Pushdown Automata based on slides written by Chris
Pushdown Automata (based on slides written by Chris Umans) • • PDA = NFA + Stack They accept context-free languages 12/2/2020 COSC 417 - PDA 1
Machine view of FA input tape 0 1 1 0 0 1 q 0 finite control 12/2/2020 COSC 417 - PDA 2
Machine view of FA input tape 0 1 1 0 0 1 q 3 finite control 12/2/2020 COSC 417 - PDA 3
Machine view of FA input tape 0 1 1 0 0 1 q 1 finite control 12/2/2020 COSC 417 - PDA 4
Machine view of FA input tape 0 1 1 0 0 1 q 2 finite control 12/2/2020 etc… COSC 417 - PDA 5
A more powerful machine • limitation of FA related to fact that they can only “remember” a bounded amount of information • What is the simplest alteration that adds unbounded “memory” to our machine? • Should be able to recognize, e. g. , {0 n 1 n: n ≥ 0} 12/2/2020 COSC 417 - PDA 6
Pushdown Automata finite control input tape 0 1 1 0 0 1 q 0 New capabilities: (infinite) stack 0 1 1 0 : 12/2/2020 • can push symbol onto stack • can pop symbol off of stack COSC 417 - PDA 7
Pushdown Automata finite control input tape 0 0 1 1 1 0 0 1 q 0 $ (infinite) stack : 12/2/2020 COSC 417 - PDA 8
Pushdown Automata finite control input tape 0 0 1 1 1 0 0 1 q 1 0 (infinite) $ stack : 12/2/2020 COSC 417 - PDA 9
Pushdown Automata finite control input tape 0 0 1 1 1 0 0 1 q 1 (infinite) stack 0 0 $ : 12/2/2020 COSC 417 - PDA 10
Pushdown Automata finite control input tape 0 0 1 1 1 0 0 1 q 2 0 (infinite) $ stack : 12/2/2020 COSC 417 - PDA 11
Pushdown Automata finite control input tape 0 0 1 1 1 0 0 1 q 2 $ (infinite) : stack 12/2/2020 COSC 417 - PDA Note: often start by pushing $ marker onto stack so that we can detect “empty stack” 12
Pushdown Automata (PDA) • We will define nondeterministic pushdown automata immediately – potentially several choices of “next step” – PDA – by default they are nondeterministic – Deterministic PDA are weaker • Two ways to describe NPDA – diagram – formal definition 12/2/2020 COSC 417 - PDA 13
NPDA diagram transition label: (tape symbol read, stack symbol popped → stack symbol pushed) 0, ε → 0 ε, ε → $ start state 1, 0 → ε states accept states ε, $ → ε transitions 12/2/2020 COSC 417 - PDA 1, 0 → ε 14
NPDA operation • 12/2/2020 COSC 417 - PDA 15
Example NPDA 0, ε → 0 ε, ε → $ 1, 0 → ε ε, $ → ε 1, 0 → ε • tape: 0 0 1 1 12/2/2020 Stack contents: $ COSC 417 - PDA 16
Example NPDA 0, ε → 0 ε, ε → $ 1, 0 → ε ε, $ → ε 1, 0 → ε • tape: 0 0 1 1 12/2/2020 Stack contents: 0 $ COSC 417 - PDA 17
Example NPDA 0, ε → 0 ε, ε → $ 1, 0 → ε ε, $ → ε 1, 0 → ε • tape: 0 0 1 1 12/2/2020 Stack contents: 0 0 $ COSC 417 - PDA 18
Example NPDA 0, ε → 0 ε, ε → $ 1, 0 → ε ε, $ → ε 1, 0 → ε • tape: 0 0 1 1 12/2/2020 Stack contents: 0 0 $ COSC 417 - PDA 19
Example NPDA 0, ε → 0 ε, ε → $ 1, 0 → ε ε, $ → ε 1, 0 → ε • tape: 0 0 1 1 12/2/2020 Stack contents: 0 $ COSC 417 - PDA 20
Example NPDA 0, ε → 0 ε, ε → $ 1, 0 → ε ε, $ → ε 1, 0 → ε • tape: 0 0 1 1 accepted 12/2/2020 Stack contents: $ COSC 417 - PDA 21
Example NPDA 0, ε → 0 ε, ε → $ 1, 0 → ε ε, $ → ε 1, 0 → ε • tape: 0 0 1 12/2/2020 Stack contents: $ COSC 417 - PDA 22
Example NPDA 0, ε → 0 ε, ε → $ 1, 0 → ε ε, $ → ε 1, 0 → ε • tape: 0 0 1 12/2/2020 Stack contents: 0 $ COSC 417 - PDA 23
Example NPDA 0, ε → 0 ε, ε → $ 1, 0 → ε ε, $ → ε 1, 0 → ε • tape: 0 0 1 12/2/2020 Stack contents: 0 0 $ COSC 417 - PDA 24
Example NPDA 0, ε → 0 ε, ε → $ 1, 0 → ε ε, $ → ε 1, 0 → ε • tape: 0 0 1 12/2/2020 Stack contents: 0 0 $ COSC 417 - PDA 25
Example NPDA 0, ε → 0 ε, ε → $ 1, 0 → ε ε, $ → ε 1, 0 → ε • tape: 0 0 1 not accepted 12/2/2020 Stack contents: 0 $ COSC 417 - PDA 26
Example NPDA 0, ε → 0 ε, ε → $ 1, 0 → ε ε, $ → ε 1, 0 → ε • What language does this NPDA accept? 12/2/2020 COSC 417 - PDA 27
Informal description • State q_0: push $, move to state q_1 • State q_1: as long as we see 0, we push 0, and stay in q_1; When the first 1 is seen, pop 0, and move to q_2 • State q_2: as long as we see 1, pop 0, and stay in q_2. If by the time we see <blank>, the top contains $, go to q_accept. In all other situations, reject. 12/2/2020 COSC 417 - PDA 28
Formal definition of NPDA • 12/2/2020 COSC 417 - PDA 29
Formal definition of NPDA • 12/2/2020 COSC 417 - PDA 30
Example of formal definition 0, ε → 0 ε, ε → $ q 0 q 1 1, 0 → ε ε, $ → ε q 3 q 2 1, 0 → ε • 12/2/2020 • • • δ(q 0, ε, ε) = {(q 1, $)} δ(q 1, 0, ε) = {(q 1, 0)} δ(q 1, 1, 0) = {(q 2, ε)} δ(q 2, ε, $) = {(q 3, ε)} COSC 417 - PDA other values of δ( • , • ) equal {} 31
Exercise Design a NPDA for the language {aibjck : i, j, k ≥ 0 and i = j or i = k} 12/2/2020 COSC 417 - PDA 32
Context-free grammars and languages • languages recognized by a (N)FA are exactly the languages described by regular expressions, and they are called the regular languages • languages recognized by a NPDA are the context-free languages, so the languages generated by context-free grammars. 12/2/2020 COSC 417 - PDA 33
- Slides: 33