Pushdown Automata

23
CS 3240 – Chapter 7

description

CS 3240 – Chapter 7. Pushdown Automata. Where Are We?. A Pushdown Automaton Machine for Context-Free Languages. Take an FA and add a stack A restricted form of unbounded memory Operations: Pop Push Ignore ( λ ) (Pop always precedes push). PDA Operations. - PowerPoint PPT Presentation

Transcript of Pushdown Automata

Page 1: Pushdown Automata

CS 3240 – Chapter 7

Page 2: Pushdown Automata

Language Machine Grammar

Regular Finite Automaton Regular Expression,Regular Grammar

Context-Free Pushdown Automaton

Context-Free Grammar

Recursively Enumerable

Turing Machine Unrestricted Phrase-Structure Grammar

2CS 3240 - Introduction

Page 3: Pushdown Automata

Take an FA and add a stack A restricted form of unbounded memory

Operations: Pop Push Ignore (λ) (Pop always precedes push)

3CS 3240 - Pushdown Automata

Page 4: Pushdown Automata

Three items per transition edge <read>,<pop>,<push> any or all could be λ

A PDA accepts when: An accepting state is reached, and The stack is empty

▪ Different from book!

▪ The machine crashes when no move is possible▪ implicit jail

4CS 3240 - Pushdown Automata

Page 5: Pushdown Automata

A deterministic PDA (no choices; λ is okay sometimes). The stack alphabet (Γ = {X}) can differ from the input alphabet (Σ = {a, b}) .

Trace aabb…

5CS 3240 - Pushdown Automata

Page 6: Pushdown Automata

q0 aabb λq0 abb Xq0 bb XXq1 b Xq1 λ λ

6CS 3240 - Pushdown Automata

Traditional notation (see book):

(q0,aabb, λ) ⊢ (q0,abb,X) ⊢ (q0,bb,XX) ⊢ (q1,b,X) ⊢ (q1,λ, λ)

Also: (q0,aabb,λ) ⊢* (q1,λ, λ) (⇒ aabb ∈ L)

Page 7: Pushdown Automata

7CS 3240 - Pushdown Automata

Page 8: Pushdown Automata

8CS 3240 - Pushdown Automata

How would you do a2nbn?

Page 9: Pushdown Automata

CS 3240 - Pushdown Automata 9

Each b must pop 2 X’s

Page 10: Pushdown Automata

Is this deterministic?

Trace the string abaacaaba.

10CS 3240 - Pushdown Automata

Page 11: Pushdown Automata

Input: (state-1, input character, pop character)

Output: (state-2, push character(s))

Example: The edge (a,λ,a) on previous slide:

δ(q0,a,λ) = (q0,a)

Exercise: Rewrite wcwR in functional form

CS 3240 - Pushdown Automata 11

Page 12: Pushdown Automata

Is this deterministic?Trace the string abaaaaaba.Trace the string abaabaaba.Trace the string abaaaaba.

12CS 3240 - Pushdown Automata

Page 13: Pushdown Automata

CS 3240 - Pushdown Automata 13

Trace aaabbbb

The grammar:

S → aSb | aSbb | λ

Page 14: Pushdown Automata

CS 3240 - Pushdown Automata 14

Trace ababbaab

Page 15: Pushdown Automata

CS 3240 - Pushdown Automata 15

Page 16: Pushdown Automata

CS 3240 - Pushdown Automata 16

Try abababbbb.How would you do Twicea?

Reasoning: There must be 2 b’s for every a. When we read an a, there are three possibilities:

1)Its 2 b’s have already been read2)1 b has been read and 1 remains3)Both b’s are yet to be read

Page 17: Pushdown Automata

CS 3240 - Pushdown Automata 17

Page 18: Pushdown Automata

CS 3240 - Pushdown Automata 18

Page 19: Pushdown Automata

CS 3240 - Pushdown Automata 19

Page 20: Pushdown Automata

Q: set of states∑: input alphabetΓ: stack alphabetδ: Q x (∑∪λ) x (Γ∪λ) → finite subsets

of Q x Γ*

q0: start stateF ⊆ Q: final states

(z ⋲ Γ: optional stack start symbol)CS 3240 - Pushdown Automata 20

Page 21: Pushdown Automata

Not strictly necessary Can serve as a “bottom marker” to allow

detection of an empty stack A convenience

Can make things easier to design/understand

Sometimes handy when seeking an associated CFG

Can eliminate some lambda pops▪ Handy later

CS 3240 - Pushdown Automata 21

Page 22: Pushdown Automata

CS 3240 - Pushdown Automata 22

Page 23: Pushdown Automata

CS 3240 - Pushdown Automata 23