Pushdown stack automata
Sponsored Links
This presentation is the property of its rightful owner.
1 / 45

Pushdown Stack Automata PowerPoint PPT Presentation


  • 70 Views
  • Uploaded on
  • Presentation posted in: General

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 )

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

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)

if derives(x,u) return true

3. return false //no successful branch

EG:S  # | aSa | bSb


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


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


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


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


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


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


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


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


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


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


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)


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 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 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


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


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


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


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


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

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.


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 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 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 Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


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 Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


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 Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


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 Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


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 Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


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 Version

a , ea

b , eb

a , ae

b , be

e , e$

#, ee

e , $e

Input:

aaab#baaa


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!


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.


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


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

(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

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


  • Login