Pushdown stack automata
Download
1 / 45

Pushdown Stack Automata - PowerPoint PPT Presentation


  • 91 Views
  • Uploaded on

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 )

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Pushdown Stack Automata' - magdalen


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Pushdown stack automata

Pushdown Stack Automata

Zeph Grunschlag


Agenda
Agenda

  • Pushdown Automata

    • Stacks and recursiveness

    • Formal Definition


From cfg s to stack machines
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


From cfg s to stack machines1
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 ?


From cfg s to stack machines2
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?


From cfg s to stack machines3
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.


From cfg s to stack machines4

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


From cfg s to stack machines5

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


From cfg s to stack machines6

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


From cfg s to stack machines7

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


From cfg s to stack machines8

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


From cfg s to stack machines9

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


From cfg s to stack machines10

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


From cfg s to stack machines11

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


From cfg s to stack machines12

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


From cfg s to stack machines13

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)


From cfg s to stack machines14

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


From cfg s to stack machines15

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


From cfg s to stack machines16

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


From cfg s to stack machines17

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


From cfg s to stack machines18

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


From cfg s to stack machines19

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


From cfg s to stack machines20

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


From cfg s to stack machines21

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


Pda s la sipser
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.


Sipser s version

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


Sipser s version1
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


Sipser s version2
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


Sipser s version3
Sipser’s Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


Sipser s version4
Sipser’s Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


Sipser s version5
Sipser’s Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


Sipser s version6
Sipser’s Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


Sipser s version7
Sipser’s Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


Sipser s version8
Sipser’s Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


Sipser s version9
Sipser’s Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


Sipser s version10
Sipser’s Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


Sipser s version11
Sipser’s Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


Sipser s version12
Sipser’s Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


Sipser s version13
Sipser’s Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


Sipser s version14
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!


Pda formal definition
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.


Pda formal definition1
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


Pda formal definition2
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


Pda exercise
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.


Pda example no bubbles
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


ad