1 / 45

Pushdown Stack Automata

Pushdown Stack Automata. Zeph Grunschlag. Agenda. Pushdown Automata Stacks and recursiveness Formal Definition. From CFG’s to Stack Machines. CFG’s naturally define recursive procedure: boolean derives(strings x, y) 1. if (x==y ) return true 2. for(all u y )

magdalen
Download Presentation

Pushdown Stack Automata

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pushdown Stack Automata Zeph Grunschlag

  2. Agenda • Pushdown Automata • Stacks and recursiveness • Formal Definition

  3. From CFG’s to Stack Machines CFG’s naturally define recursive procedure: boolean derives(strings x, y) 1. if (x==y) return true 2. for(all uy) if derives(x,u) return true 3. return false //no successful branch EG: S  # | aSa | bSb

  4. From CFG’s to Stack Machines By general principles, can carry out any recursive computation on a stack. Can do it on a restricted version of an activation record stack, called a “Pushdown (Stack) Automaton” or PDA for short. Q: What is the language generated by S  # | aSa | bSb ?

  5. From CFG’s to Stack Machines A: Palindromes in {a,b,#}* containing exactly one #-symbol. Q: Using a stack, how can we recognize such strings?

  6. From CFG’s to Stack Machines A: Use a three phase process: • Push mode: Before reading “#”, push everything on the stack. • Reading “#” switches modes. • Pop mode: Read remaining symbols making sure that each new read symbol is identical to symbol popped from stack. Accept if able to empty stack completely. Otherwise reject, and reject if could not pop somewhere.

  7. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP

  8. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baa

  9. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baa

  10. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baa

  11. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baa

  12. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baa

  13. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baa

  14. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baa

  15. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baa

  16. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baa REJECT (nonempty stack)

  17. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baaa

  18. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baaa

  19. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baaa Pause input

  20. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baaa ACCEPT

  21. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baaaa

  22. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baaaa

  23. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baaaa Pause input

  24. ACCEPT From CFG’s to Stack Machines read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? (1) PUSH (3) POP Input: aaab#baaaa CRASH

  25. PDA’s à la Sipser To aid analysis, theoretical stack machines restrict the allowable operations. Each text-book author has his own version. Sipser’s machines are especially simple: • Push/Pop rolled into a single operation: replace top stack symbol • No intrinsic way to test for empty stack • Epsilon’s used to increase functionality, result in default nondeterministic machines.

  26. ACCEPT Sipser’s Version read == peek? Pop Else: CRASH! read a or b ? Push it (2) read #? (ignore stack) empty stack? Becomes: (1) PUSH (3) POP a , ea b , eb a , ae b , be e , e$ #, ee e , $e

  27. Sipser’s Version x, y z p q Meaning of labeling convention: If at p and next input x and top stack y, thengo to qand replace y by z on stack. • x = e: ignore input, don’t read • y = e: ignore top of stack and push z • z = e: pop y

  28. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e push $ to detect empty stack

  29. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e Input: aaab#baaa

  30. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e Input: aaab#baaa

  31. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e Input: aaab#baaa

  32. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e Input: aaab#baaa

  33. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e Input: aaab#baaa

  34. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e Input: aaab#baaa

  35. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e Input: aaab#baaa

  36. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e Input: aaab#baaa

  37. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e Input: aaab#baaa

  38. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e Input: aaab#baaa

  39. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e Input: aaab#baaa

  40. Sipser’s Version a , ea b , eb a , ae b , be e , e$ #, ee e , $e Input: aaab#baaa ACCEPT!

  41. PDAFormal Definition DEF: A pushdown automaton (PDA) is a 6-tuple M = (Q, S, G, d, q0, F ). Q, S, and q0, are the same as for an FA. G is the tape alphabet. d is as follows: So given a state p, an input letter x and a tape letter y, d(p,x,y) gives all (q,z) where q is a target state and z astack replacement for y.

  42. PDAFormal Definition Q: What is d(p,x,y) in each case? • d(0,a,b) • d(0,e,e) • d(1,a,e) • d(3,e,e) a , ea b , eb a , ae b , be a , e e 0 1 2 3 e , e$ b, e$ e , $e

  43. PDAFormal Definition A: • d(0,a,b) =  • d(0,e,e) = {(1,$)} • d(1,a,e) = {(0,e),(1,a)} • d(3,e,e) =  a , ea b , eb a , ae b , be a , e e 0 1 2 3 e , e$ b, e$ e , $e

  44. PDA Exercise (Sipser 2.6.a) Draw the PDA acceptor for L = { x  {a,b}* | na(x) = 2nb(x) } NOTE: The empty string is in L.

  45. PDA Example.No-Bubbles a, $ $ a, AA e, eA a , ae e, Ae e, $$ b, Ae e , e$ e , $e e, ea b, $ $ b, a a e, ea

More Related