pushdown automata
play

Pushdown Automata Stack PDAs States 1 a , b c The States q 1 q - PDF document

Review Languages and Grammars Alphabets, strings, languages Regular Languages CS 301 - Lecture 11 Deterministic Finite and Nondeterministic Automata Equivalence of NFA and DFA Nondeterministic Pushdown Regular Expressions


  1. Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages CS 301 - Lecture 11 – Deterministic Finite and Nondeterministic Automata – Equivalence of NFA and DFA Nondeterministic Pushdown – Regular Expressions – Regular Grammars Automata – Properties of Regular Languages – Languages that are not regular and the pumping lemma Fall 2008 • Context Free Languages – Context Free Grammars – Derivations: leftmost, rightmost and derivation trees – Parsing and ambiguity – Simplifying Grammars and Normal Forms • Today: – Nondeterministic Pushdown Automata Pushdown Automaton -- PDA Input String Pushdown Automata Stack PDAs States 1

  2. a , b → c The States q 1 q 2 Pop Input Push symbol symbol symbol input     a a a , b → c q 1 q 2 stack c b top Replace h h e e $ $ a , λ → c a , b → λ q 1 q 2 q 1 q 2 input input         a a a a stack stack c b top b b top Push Pop h h h h e e e e $ $ $ $ 2

  3. A Possible Transition a , λ → λ q 1 q 2 a , $ → λ q 1 q 2 input input     a a     a a stack empty stack Pop top $ b b top No Change h h e e $ $ A Bad Transition A Bad Transition a , c a , b c → λ → q 1 q 2 q 1 q 2 input input     a a Empty stack Empty stack HALT HALT The automaton Halts in state q 1 The automaton Halts in state q 1 and Rejects the input string and Rejects the input string 3

  4. A Good Transition No transition is allowed to be followed When the stack is empty a , $ b → q 1 q 2 input x , y z →     a a q 1 q 2 stack Pop Empty stack top b $ NPDA: Non-Deterministic Non-Determinism PDA q 2 Example: a , b → c λ , b → c q 1 q 1 q 2 transition λ − a , λ → a b , a → λ a , b → c q 3 These are allowed transitions in a λ , λ → λ b , a → λ λ , $ → $ q 0 q 1 q 2 q 3 Non-deterministic PDA (NPDA) 4

  5. Execution Example: Time 0 Time 1 Input Input a a a a a a b b b b b b $ $ Stack Stack current a , λ → a b , a → λ a , λ → a b , a → λ state λ , λ → λ b , a → λ λ , $ → $ λ , λ → λ b , a → λ λ , $ → $ q q 1 q 2 q 3 q 0 q 1 q 2 q 3 0 Time 2 Time 3 Input Input a a a a a a a a b b b b b b a $ $ Stack Stack a , λ → a b , a → λ a , λ → a b , a → λ λ , λ → λ b , a → λ λ , $ → $ λ , λ → λ b , a → λ λ , $ → $ q 0 q 1 q 2 q 3 q 0 q 1 q 2 q 3 5

  6. Time 4 Time 5 a a Input Input a a a a a a a a b b b b b b a a $ $ Stack Stack a , λ → a b , a → λ a , λ → a b , a → λ λ , λ → λ b , a → λ λ , $ → $ λ , λ → λ b , a → λ λ , $ → $ q 0 q 1 q 2 q 3 q 0 q 1 q 2 q 3 Time 6 Time 7 Input Input a a a a a a a a a b b b b b b $ $ Stack Stack a , λ → a b , a → λ a , λ → a b , a → λ λ , λ → λ b , a → λ λ , $ → $ λ , λ → λ b , a → λ λ , $ → $ q 0 q 1 q 2 q 3 q 0 q 1 q 2 q 3 6

  7. Time 8 A string is accepted if there is Input a computation such that: a a a b b b $ All the input is consumed Stack AND The last state is a final state a , λ → a b , a → λ accept At the end of the computation, λ , λ → λ b , a → λ λ , $ → $ we do not care about the stack contents q 0 q 1 q 2 q 3 In general, n n L { a b : n 0 } = ≥ The input string aaabbb is accepted by the NPDA: is the language accepted by the NPDA: a , λ → a b , a → λ a , λ → a b , a → λ λ , λ → λ b , a → λ λ , $ → $ λ , λ → λ b , a → λ λ , $ → $ q 0 q 1 q 2 q 3 q 0 q 1 q 2 q 3 7

  8. Execution Example: Time 0 Another NPDA example Input NPDA M a a b b R L ( M ) { ww } = $ Stack a , a a , a λ → a , a λ → a , a → λ → λ b , b b , b λ → b , b λ → b , b → λ → λ λ , λ → λ λ , $ → $ λ , λ → λ λ , $ → $ q 2 q 2 q 0 q 1 q 0 q 1 Time 1 Time 2 Input Input b a a a a b b b b a a $ $ Stack Stack a , a a , a λ → a , a λ → a , a → λ → λ b , b b , b b , b b , b λ → λ → → λ → λ λ , λ → λ λ , $ → $ λ , λ → λ λ , $ → $ q 2 q 2 q 0 q 1 q 0 q 1 8

  9. Time 3 Time 4 Input Input b b a a a a b b b b a a Guess the middle $ $ of string Stack Stack a , a a , a λ → a , a λ → a , a → λ → λ b , b b , b λ → b , b λ → b , b → λ → λ λ , λ → λ λ , $ → $ λ , λ → λ λ , $ → $ q 2 q 2 q 0 q 1 q 0 q 1 Time 5 Time 6 Input Input a a a a b b b b a $ $ Stack Stack a , a a , a λ → a , a λ → a , a → λ → λ b , b b , b b , b b , b λ → λ → → λ → λ accept λ , λ → λ λ , $ → $ λ , λ → λ λ , $ → $ q 2 q 2 q q 0 q 0 q 1 1 9

  10. Rejection Example: Time 0 Time 1 Input Input a a b b b b b b a $ $ Stack Stack a , a a , a λ → a , a λ → a , a → λ → λ b , b b , b λ → b , b λ → b , b → λ → λ λ , λ → λ λ , $ → $ λ , λ → λ λ , $ → $ q 2 q 2 q 0 q 1 q 0 q 1 Time 2 Time 3 Input Input b b a a b b b b b b a a Guess the middle $ $ of string Stack Stack a , a a , a λ → a , a λ → a , a → λ → λ b , b b , b b , b b , b λ → λ → → λ → λ λ , λ → λ λ , $ → $ λ , λ → λ λ , $ → $ q 2 q 2 q 0 q 1 q 0 q 1 10

  11. Time 4 Time 5 There is no possible transition. Input Input b a a Input is not b b b b b b a a consumed $ $ Stack Stack a , a a , a λ → a , a λ → a , a → λ → λ b , b b , b λ → b , b λ → b , b → λ → λ λ , λ → λ λ , $ → $ λ , λ → λ λ , $ → $ q 2 q q 2 q 0 q 1 q 0 1 Another computation on same string: Time 1 Input Input Time 0 a a b b b b b b a $ $ Stack Stack a , a a , a λ → a , a λ → a , a → λ → λ b , b b , b b , b b , b λ → λ → → λ → λ λ , λ → λ λ , $ → $ λ , λ → λ λ , $ → $ q 2 q 2 q 0 q 1 q 0 q 1 11

  12. Time 2 Time 3 b Input Input b b a a b b b b b b a a $ $ Stack Stack a , a a , a λ → a , a λ → a , a → λ → λ b , b b , b λ → b , b λ → b , b → λ → λ λ , λ → λ λ , $ → $ λ , λ → λ λ , $ → $ q 2 q 2 q 0 q 1 q 0 q 1 Time 4 Time 5 b b b b Input Input No final state b b a a is reached b b b b b b a a $ $ Stack Stack a , a a , a λ → a , a λ → a , a → λ → λ b , b b , b b , b b , b λ → λ → → λ → λ λ , λ → λ λ , $ → $ λ , λ → λ λ , $ → $ q 2 q 2 q 0 q 1 q 0 q 1 12

  13. A string is rejected if there is There is no computation no computation such that: that accepts string abbb abbb ∉ L ( M ) All the input is consumed AND The last state is a final state a , a λ → a , a → λ b , b λ → b , b → λ At the end of the computation, we do not care about the stack contents λ , λ → λ λ , $ → $ q 2 q 0 q 1 In other words, a string is rejected Another NPDA example if in every computation with this string: NPDA M n m L ( M ) { a b : n m 1 } = ≥ − The input cannot be consumed This NPDA generates: OR The input is consumed and the last and for each substring u state is not a final state OR a , a λ → The stack head moves below the b , a → λ bottom of the stack q 0 b , $ → λ 13

  14. Execution Example: Time 0 Time 1 Input Input b b a a a a a $ $ a , a a , a λ → λ → Stack Stack b , a b , a → λ → λ b , $ b , $ → λ → λ q 0 q 0 Time 2 Time 3 Input Input a b b a a a a a a $ $ a , a a , a λ → λ → Stack Stack b , a b , a → λ → λ b , $ b , $ → λ → λ accept q 0 q 0 14

  15. Rejection example: Time 0 Time 1 Input Input b b b b b b a a a $ $ a , a λ → Stack Stack b , a → λ b , $ → λ q 0 q 0 Time 2 Time 3 Input Input b b b b b b a a $ a , a a , a λ → λ → Stack Stack b , a b , a → λ → λ b , $ b , $ → λ → λ q 0 q 0 15

  16. Time 4 Pushing Strings Input Pop Input Push b b b a symbol symbol string a , a λ → Stack b , a → λ b , $ a , b → w → λ q 1 q 2 Halt and Reject q 0 Example: What’s Next a , b → cdf q 1 q 2 • Read – Linz Chapter 1,2.1, 2.2, 2.3, (skip 2.4), 3, 4, 5, 6.1, 6.2, (skip 6.3), 7.1, and input 7.2   a – JFLAP Chapter 1, 2.1, (skip 2.2), 3, 4, 5, 6, 7   a • Next Lecture Topics from Chapter 7.2 – Pushdown Automata and Context Free Grammars • Quiz 2 in Recitation on Wednesday 10/1 – Covers Linz 3, 4 and JFLAP 3, 4 pushed c – Closed book, but you may bring one sheet of 8.5 x 11 inch paper with any stack d string notes you like. top f – Quiz will take the full hour b Push • Homework h h – Homework Due Thursday e e $ $ 16

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend