346
Pushdown Automata

Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Pushdown Automata

Page 2: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Announcements

● Problem Set 5 due this Friday at 12:50PM.● Late day extension: Using a 72-hour late day

now extends the due date to 12:50PM on Tuesday, February 19th.

Page 3: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

● The Weak Pumping Lemma for Regular Languages states that

For any regular language L,

There exists a positive natural number n such that

For any w ∈ L with |w| ≥ n,

There exists strings x, y, z such that

For any natural number i,

w = xyz,

y ≠ ε

xyiz ∈ L

w can be broken into three pieces,

where the middle piece can be replicated zero or more times.

where the middle piece isn't empty,

Page 4: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Counting Symbols

● Consider the alphabet Σ = { 0, 1 } and the language

L = { w ∈ Σ* | w contains an equal number of 0s and 1s. }

● For example:● 01 ∈ L● 110010 ∈ L● 11011 ∉ L

● Question: Is L a regular language?

Page 5: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

0 01 1 0 1

Page 6: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

0 01 1 0 1

Page 7: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

01 0 1

Page 8: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

0 01 1 0 1

Page 9: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

0 01 1 0 101

Page 10: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

0 01 1 0 101 01

Page 11: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Page 12: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

0 01 1

Page 13: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

0 01 1

Page 14: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

01 10

Page 15: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Page 16: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

01 10

Page 17: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

01 10 01 10

Page 18: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

01 10 01 10 01 10

Page 19: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

An Incorrect Proof

Theorem: L is regular.

Proof: We show that L satisfies the condition ofthe pumping lemma. Let n = 2 and considerany string w ∈ L such that |w| ≥ 2. Then wecan write w = xyz such that x = z = ε andy = w, so y ≠ ε. Then for any natural number i,xyiz = wi, which has the same number of 0s and1s. Since L passes the conditions of the weakpumping lemma, L is regular. ■

Page 20: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

An Incorrect Proof

Theorem: L is regular.

Proof: We show that L satisfies the condition ofthe pumping lemma. Let n = 2 and considerany string w ∈ L such that |w| ≥ 2. Then wecan write w = xyz such that x = z = ε andy = w, so y ≠ ε. Then for any natural number i,xyiz = wi, which has the same number of 0s and1s. Since L passes the conditions of the weakpumping lemma, L is regular. ■

Page 21: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

● The Weak Pumping Lemma for Regular Languages states that

For any regular language L,

There exists a positive natural number n such that

For any w ∈ L with |w| ≥ n,

There exists strings x, y, z such that

For any natural number i,

w = xyz,

y ≠ ε

xyiz ∈ Lwhere the middle piece can be replicated zero or more times.

where the middle piece isn't empty,

w can be broken into three pieces,

Page 22: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

● The Weak Pumping Lemma for Regular Languages states that

For any regular language L,

There exists a positive natural number n such that

For any w ∈ L with |w| ≥ n,

There exists strings x, y, z such that

For any natural number i,

w = xyz,

y ≠ ε

xyiz ∈ Lwhere the middle piece can be replicated zero or more times.

where the middle piece isn't empty,

w can be broken into three pieces,

This says nothing about languages that aren't regular!

This says nothing about languages that aren't regular!

Page 23: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Caution with the Pumping Lemma

● The weak and full pumping lemmas describe a necessary condition of regular languages.

● If L is regular, L passes the conditions of the pumping lemma.

● The weak and full pumping lemmas are not a sufficient condition of regular languages.

● If L is not regular, it still might pass the conditions of the pumping lemma!

● If a language fails the pumping lemma, it is definitely not regular.

● If a language passes the pumping lemma, we learn nothing about whether it is regular or not.

Page 24: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

L is Not Regular

● The language L can be proven not to be regular using a stronger version of the pumping lemma.

● To see the full pumping lemma, we need to revisit our original insight.

Page 25: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

An Important Observation

q1

q2

q3

q0

0

1 1

0 1

q5

1

0

0

0, 1

0, 1

q4

start

0 1 1 0 1 1 0 1 1 0 1 1 1

Page 26: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

An Important Observation

q1

q2

q3

q0

0

1 1

0 1

q5

1

0

0

0, 1

0, 1

q4

start

0q

0

1 1 0 1 1 0 1 1 0 1 1 1q

1q

2q

3q

2q

4q

3q

1q

2q

3q

1q

2q

3q

1

Page 27: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

An Important Observation

q1

q2

q3

q0

0

1 1

0 1

q5

1

0

0

0, 1

0, 1

q4

start

0q

0

1 1 0 1 1 0 1 1 0 1 1 1q

1q

2q

3q

2q

4q

3q

1q

2q

3q

1q

2q

3q

1

Page 28: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

An Important Observation

q1

q2

q3

q0

0

1 1

0 1

q5

1

0

0

0, 1

0, 1

q4

start

0q

0

1 1 0 1 1 0 1 1 0 1 1 1q

1q

2q

3q

2q

4q

3q

1q

2q

3q

1q

2q

3q

1

Page 29: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Weak Pumping Lemma Intuition

● Let D be a DFA with n states.● Any string w accepted by D that has length at

least n must visit some state twice. within its first n characters.● Number of states visited is equal to |w| + 1.● By the pigeonhole principle, some state is

duplicated.

● The substring of w in-between those revisited states can be removed, duplicated, tripled, quadrupled, etc. without changing the fact that w is accepted by D.

Page 30: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Pumping Lemma Intuition

● Let D be a DFA with n states.● Any string w accepted by D that has length at

least n must visit some state twice within its first n characters.● Number of states visited is equal n + 1.● By the pigeonhole principle, some state is

duplicated.

● The substring of w in-between those revisited states can be removed, duplicated, tripled, quadrupled, etc. without changing the fact that w is accepted by D.

Page 31: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Weak Pumping Lemma

For any regular language L,

There exists a positive natural number n such that

For any w ∈ L with |w| ≥ n,

There exists strings x, y, z such that

For any natural number i,

w = xyz,

y ≠ ε

xyiz ∈ L where the middle piece can be replicated zero or more times.

where the middle piece isn't empty,

w can be broken into three pieces,

Page 32: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

For any regular language L,

There exists a positive natural number n such that

For any w ∈ L with |w| ≥ n,

There exists strings x, y, z such that

For any natural number i,

w = xyz,

|xy| ≤ n,

y ≠ ε

xyiz ∈ L where the middle piece can be replicated zero or more times.

where the middle piece isn't empty,

w can be broken into three pieces,

where the first two pieces occur at the start of the string,

Page 33: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Why This Change Matters

● The restriction |xy| ≤ n means that we can limit where the string to pump must be.

● If we specifically craft the first n characters of the string to pump, we can force y to have a specific property.

● We can then show that y cannot be pumped arbitrarily many times.

Page 34: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Page 35: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Suppose the pumping length is 4.

Page 36: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Suppose the pumping length is 4.

0 00 0 1 1 1 1

Page 37: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Suppose the pumping length is 4.

0 00 0 1 1 1 1

Since |xy| 4, the ≤

string to pump must be somewhere in

here.

Since |xy| 4, the ≤

string to pump must be somewhere in

here.

Page 38: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Suppose the pumping length is 4.

0 00 0 1 1 1 1

Page 39: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Suppose the pumping length is 4.

0 0 1 1 1 1

Page 40: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Suppose the pumping length is 4.

0 0 1 1 1 1

Page 41: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Suppose the pumping length is 4.

0 00 0 1 1 1 1

Page 42: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Suppose the pumping length is 4.

1 1 1 1

Page 43: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Suppose the pumping length is 4.

1 1 1 1

Page 44: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Suppose the pumping length is 4.

0 00 0 1 1 1 1

Page 45: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Suppose the pumping length is 4.

00 0 1 1 1 1

Page 46: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Pumping Lemma

L = { w ∈ {0, 1}*| w contains an equal number of 0s and 1s. }

Suppose the pumping length is 4.

00 0 1 1 1 1

Page 47: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

L = { w ∈ {0, 1}* | w has an equal number of 0s and 1s }

Theorem: L is not regular.

Proof: By contradiction; assume that L is regular. Let nbe the length guaranteed by the pumping lemma.Consider the string w = 0n1n. Then |w| = 2n ≥ n andw ∈ L. Therefore, there exist strings x, y, and z suchthat w = xyz, |xy| ≤ n, y ≠ ε, and for any natural number i, xyiz ∈ L. Since |xy| ≤ n, y must consist solelyof 0s. But then xy2z = 0n+|y|1n, and since |y| > 0, wehave that xy2z ∉ L.

We have reached a contradiction, so our assumptionwas wrong and L is not regular. ■

Page 48: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Summary of the Pumping Lemma

● Using the pigeonhole principle, we can prove the weak pumping lemma and pumping lemma.

● These lemmas describe essential properties of the regular languages.

● Any language that fails to have these properties cannot be regular.

Page 49: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Beyond Finite Automata

Page 50: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Where We Are

● Our study of the regular languages gives us an exact characterization of problems that can be solved by finite computers.

● Not all languages are regular.● How do we build more powerful

computing devices?

Page 51: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Problem

● Finite automata accept precisely the regular languages.

● We may need unbounded memory to recognize context-free languages.● e.g. { 0n1n | n ∈ ℕ } requires unbounded

counting.

● How do we build an automaton with finitely many states but unbounded memory?

Page 52: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A B C A ...

The finite-state control acts as a finite memory.

The finite-state control acts as a finite memory.

The input tape holds the input string.

The input tape holds the input string.

Memory DeviceWe can add an infinite memory device the

finite-state control can use to store information.

We can add an infinite memory device the

finite-state control can use to store information.

Page 53: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Adding Memory to Automata

● We can augment a finite automaton by adding in a memory device for the automaton to store extra information.

● The finite automaton now can base its transition on both the current symbol being read and values stored in memory.

● The finite automaton can issue commands to the memory device whenever it makes a transition.● e.g. add new data, change existing data, etc.

Page 54: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Stack-Based Memory

● There are many types of memory that we might give to an automaton.● We'll see at least two this quarter.

● One of the simplest types of memory is a stack.

Page 55: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

a

Stack-Based Memory

● There are many types of memory that we might give to an automaton.● We'll see at least two this quarter.

● One of the simplest types of memory is a stack.

Page 56: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

a

Stack-Based Memory

● There are many types of memory that we might give to an automaton.● We'll see at least two this quarter.

● One of the simplest types of memory is a stack.

b

Page 57: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

a

Stack-Based Memory

● There are many types of memory that we might give to an automaton.● We'll see at least two this quarter.

● One of the simplest types of memory is a stack.

bc

Page 58: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

a

Stack-Based Memory

● There are many types of memory that we might give to an automaton.● We'll see at least two this quarter.

● One of the simplest types of memory is a stack.

bcd

Page 59: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

a

Stack-Based Memory

● There are many types of memory that we might give to an automaton.● We'll see at least two this quarter.

● One of the simplest types of memory is a stack.

bc

Page 60: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

a

Stack-Based Memory

● There are many types of memory that we might give to an automaton.● We'll see at least two this quarter.

● One of the simplest types of memory is a stack.

bce

Page 61: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

a

Stack-Based Memory

● There are many types of memory that we might give to an automaton.● We'll see at least two this quarter.

● One of the simplest types of memory is a stack.

bc

Page 62: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

a

Stack-Based Memory

● There are many types of memory that we might give to an automaton.● We'll see at least two this quarter.

● One of the simplest types of memory is a stack.

b

Page 63: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Stack-Based Memory

● Only the top of the stack is visible at any point in time.

● New symbols may be pushed onto the stack, which cover up the old stack top.

● The top symbol of the stack may be popped, exposing the symbol below it.

Page 64: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Pushdown Automata

● A pushdown automaton (PDA) is a finite automaton equipped with a stack-based memory.

● Each transition● is based on the current input symbol and the top of

the stack,● optionally pops the top of the stack, and● optionally pushes new symbols onto the stack.

● Initially, the stack holds a special symbol Z0 that

indicates the bottom of the stack.

Page 65: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Our First PDA

● Consider the language

L = { w ∈ Σ* | w is a string of balanced parentheses }

over Σ = { (, ) }

● We can exploit the stack to our advantage:

● Whenever we see a (, push it onto the stack.

● Whenever we see a ), pop the corresponding ( from the stack (or fail if not matched)

● When input is consumed, if the stack is empty, accept.

Page 66: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Our First PDA

● Consider the language

L = { w ∈ Σ* | w is a string of balanced parentheses }

over Σ = { (, ) }

● We can exploit the stack to our advantage:

● Whenever we see a (, push it onto the stack.

● Whenever we see a ), pop the corresponding ( from the stack (or fail if not matched)

● When input is consumed, if the stack is empty, accept.

Page 67: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Our First PDA

● Consider the language

L = { w ∈ Σ* | w is a string of balanced digits }

over Σ = { 0, 1 }

● We can exploit the stack to our advantage:

● Whenever we see a 0, push it onto the stack.

● Whenever we see a 1, pop the corresponding 0from the stack (or fail if not matched)

● When input is consumed, if the stack is empty, accept.

Page 68: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 69: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 70: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 71: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 72: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 73: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 74: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

A transition of the form

a, b → z

Means “If the current input symbol is a and the current stack symbol is b, then

follow this transition, pop b, and push the string z.

A transition of the form

a, b → z

Means “If the current input symbol is a and the current stack symbol is b, then

follow this transition, pop b, and push the string z.

Page 75: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

A transition of the form

a, b → z

Means “If the current input symbol is a and the current stack symbol is b, then

follow this transition, pop b, and push the string z.

A transition of the form

a, b → z

Means “If the current input symbol is a and the current stack symbol is b, then

follow this transition, pop b, and push the string z.

Page 76: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

To find an applicable transition, match the

current input/stack pair.

To find an applicable transition, match the

current input/stack pair.

A transition of the form

a, b → z

Means “If the current input symbol is a and the current stack symbol is b, then

follow this transition, pop b, and push the string z.

A transition of the form

a, b → z

Means “If the current input symbol is a and the current stack symbol is b, then

follow this transition, pop b, and push the string z.

Page 77: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 78: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 79: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

If a transition reads the top symbol of the stack, it always pops that symbol (though it

might replace it)

If a transition reads the top symbol of the stack, it always pops that symbol (though it

might replace it)

Page 80: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 81: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 82: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0Each transition then pushes some

(possibly empty) string back onto the stack. Notice that the leftmost symbol is pushed onto the top.

Each transition then pushes some (possibly empty) string back onto the

stack. Notice that the leftmost symbol is pushed onto the top.

Page 83: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 84: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 85: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 86: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 87: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 88: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 89: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 90: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

00

Page 91: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

00

Page 92: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

00

Page 93: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

00

Page 94: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 95: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

000

Page 96: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

000

Page 97: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

000

Page 98: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

000

Page 99: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

00

Page 100: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

00We now push the string onto ε

the stack, which adds no new characters. This essentially

means “pop the stack.”

We now push the string onto ε

the stack, which adds no new characters. This essentially

means “pop the stack.”

Page 101: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

00

Page 102: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

00

Page 103: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

00

Page 104: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 105: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 106: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 107: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 108: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 109: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 110: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 111: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 112: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

This transition can be taken at any time Z

0 is atop the stack, but we've

nondeterministically guessed that this would be a good time to take it.

This transition can be taken at any time Z

0 is atop the stack, but we've

nondeterministically guessed that this would be a good time to take it.

Page 113: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 114: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 115: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 116: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 117: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 118: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 0 0 1 1 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 119: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 120: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 121: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 122: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 123: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 124: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 125: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 126: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 127: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 128: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 129: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 130: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

0

Page 131: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 132: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 133: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 134: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 135: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 136: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 137: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 138: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 139: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 140: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 141: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 142: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 143: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Z0

Page 144: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 145: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 146: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 147: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 148: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 149: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 150: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Simple Pushdown Automaton

ε, Z0 → ε

start

0 1 1 0 0 1

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 151: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Language of a PDA

● Given a PDA P and a string w, P accepts w iff there is some series of choices such that when P is run on w, it ends in an accepting state.● The stack can contain any number of symbols when the

machine accepts.

● The language of a PDA is the set of strings that the PDA accepts:

ℒ(P) = { w ∈ Σ* | P accepts w } ● If P is a PDA where (ℒ P) = L, we say that P

recognizes L.

Page 152: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Note on Terminology

● Finite automata are highly standardized.● There are many equivalent but different

definitions of PDAs.● The one we will use is a slight variant on the one

described in Sipser.● Sipser does not have a start stack symbol.● Sipser does not allow transitions to push multiple

symbols onto the stack.

● Feel free to use either this version or Sipser's; the two are equivalent to one another.

Page 153: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

● A palindrome is a string that is the same forwards and backwards.

● Let Σ = {0, 1} and consider the language

PALINDROME = { w ∈ Σ* | w is a palindrome }.

● How would we build a PDA for PALINDROME?

● Idea: Push the first half of the symbols on to the stack, then verify that the second half of the symbols match.

● Nondeterministically guess when we've read half of the symbols.

● This handles even-length strings; we'll see a cute trick to handle odd-length strings in a minute.

Page 154: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

start

Page 155: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

start

0, Z0 → 0Z

0

0, 0 → 000, 1 → 01

1, Z0 → 1Z

0

1, 0 → 101, 1 → 11

Page 156: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

start

0, Z0 → 0Z

0

0, 0 → 000, 1 → 01

1, Z0 → 1Z

0

1, 0 → 101, 1 → 11

Page 157: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

start

0, Z0 → 0Z

0

0, 0 → 000, 1 → 01

1, Z0 → 1Z

0

1, 0 → 101, 1 → 11

Page 158: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

start

0, Z0 → 0Z

0

0, 0 → 000, 1 → 01

1, Z0 → 1Z

0

1, 0 → 101, 1 → 11

Page 159: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

start

0, ε → 01, ε → 1

Page 160: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

start

0, ε → 01, ε → 1

This transition indicates that the transition does not pop anything from the stack. It just pushes on

a new symbol instead.

Page 161: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

start

0, ε → 01, ε → 1

Page 162: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

start

0, ε → 01, ε → 1

Page 163: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

start

Σ, ε → Σ

Page 164: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

start

Σ, ε → Σ

The here refers to the Σ

same symbol in both contexts. It is a

shorthand for “treat any symbol in this way”Σ

The here refers to the Σ

same symbol in both contexts. It is a

shorthand for “treat any symbol in this way”Σ

Page 165: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

start

Σ, ε → Σ

Page 166: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εstart

Σ, ε → Σ

Page 167: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εstart

Σ, ε → Σ

This transition means “don't consume any input, don't change the top of the stack, and don't add anything to a stack. It's the equivalent of

an -transition in an NFA.ε

This transition means “don't consume any input, don't change the top of the stack, and don't add anything to a stack. It's the equivalent of

an -transition in an NFA.ε

Page 168: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εstart

Σ, ε → Σ 0, 0 → ε1, 1 → ε

Page 169: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εstart

Σ, ε → Σ Σ, Σ → ε

Page 170: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εstart

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 171: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εstart

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 172: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 173: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

This transition lets us consume one character before we start

matching what we just saw. This lets us match odd-length

palindromes

This transition lets us consume one character before we start

matching what we just saw. This lets us match odd-length

palindromes

Page 174: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 175: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 176: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 177: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 178: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 179: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

0

Page 180: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

0

Page 181: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

0

Page 182: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

01

Page 183: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

01

Page 184: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

01

Page 185: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

011

Page 186: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

011

Page 187: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

011

Page 188: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

011

Page 189: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

011

Page 190: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

011

Page 191: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

01

Page 192: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

01

Page 193: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

01

Page 194: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

0

Page 195: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

0

Page 196: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

0

Page 197: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 198: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 199: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 200: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 201: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 202: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 203: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 204: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 1 1 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 205: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 206: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 207: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 208: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 209: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 210: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 211: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

0

Page 212: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

0

Page 213: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

0

Page 214: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

01

Page 215: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

01

Page 216: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

01

Page 217: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

01

Page 218: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

01

Page 219: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

0

Page 220: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

0

Page 221: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

0

Page 222: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 223: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 224: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 225: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 226: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 227: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 228: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Palindromes

ε, ε → εΣ, ε → ε

start

0 1 0 1 0

Σ, ε → Σ Σ, Σ → ε

ε, Z0 → ε

Page 229: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Note on Nondeterminism

● In an NFA, we could interpret nondeterminism as being in multiple states simultaneously.

● This is only possible because NFAs have no extra storage.

q1

q1

q0

q0

q2

q2

q2

start 1 1 q2

0, 1

Page 230: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Note on Nondeterminism

● In an NFA, we could interpret nondeterminism as being in multiple states simultaneously.

● This is only possible because NFAs have no extra storage.

q1

q1

q0

q0

q2

q2

q2

start 1 1 q2

0, 1

q1

q1

q0

q0

q2

q2

q2

start 1 1 q2

0, 1

Page 231: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Note on Nondeterminism

● In an NFA, we could interpret nondeterminism as being in multiple states simultaneously.

● This is only possible because NFAs have no extra storage.

q1

q1

q0

q0

q2

q2

q2

start 1 1 q2

0, 1

Page 232: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A Note on Nondeterminism

● In a PDA, if there are multiple nondeterministic choices, you cannot treat the machine as being in multiple states at once.● Each state might have its own stack

associated with it.

● Instead, there are multiple parallel copies of the machine running at once, each of which has its own stack.

Page 233: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

● Let Σ = { int, +, *, (, ) } and consider the language

ARITH = { w ∈ Σ* | w is a legal arithmetic expression }

● Examples:int + int * int

((int + int) * (int + int)) + (int)

● Can we build a PDA for ARITH?

Page 234: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

Page 235: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

start

Page 236: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

int, ε → ε

start

Page 237: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

start

Page 238: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

(, ε → (

start

Page 239: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

(, ε → ( ), ( → ε

start

Page 240: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Page 241: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

int + int * int

Page 242: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + int * int

Page 243: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + int * int

Page 244: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + int * int

Page 245: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

int int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + int * intint

Page 246: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

int int int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + int * int

Page 247: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

int int int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + int * int+

Page 248: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

+int int int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + int * int

Page 249: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

int+int int int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + * int

Page 250: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

intint+int int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + * int

Page 251: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

intint+int int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + * int*

Page 252: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

*intint+int int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + * int

Page 253: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

int*intint+int int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + *

Page 254: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

intint*intint+int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + *

Page 255: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

intint*intint+int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + *

Page 256: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

intint*intint+int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

int + *

Page 257: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

intint*intint+int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

int + *

Page 258: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Page 259: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

))(( intint*intint+int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

int + *(( ++int intintint ))

Page 260: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

))(( intint*intint+int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + *(( ++int intintint ))

Page 261: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

))(( intint*intint+int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + *(( ++int intintint ))

Page 262: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

))(( intint*intint+int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int + *(( ++int intintint ))

Page 263: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

intint ))(( intint*intint+int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

+ *(( ++ intintint ))

Page 264: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

intintint ))(( intint*intint+

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

+ *(( ++ intintint ))

Page 265: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

+intintint ))(( intint*intint+

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

*(( ++ intintint ))

Page 266: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

++intintint ))(( intint*intint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

*(( ++ intintint ))

Page 267: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

(++intintint ))( intint*intint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

*(( ++ intintint ))

Page 268: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

((++intintint ))intint*intint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

*(( ++ intintint )) (

Page 269: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

(((++intintint ))intint*intint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

*( ++ intintint )) (

Page 270: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

((((++intintint ))intint*intint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

* ++ intintint )) ((

Page 271: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

int((((++intintint ))intint*int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

* ++ intintint )) ((

Page 272: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

intint((((++intintint ))intint*

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

* ++ intintint )) ((

Page 273: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

*intint((((++intintint ))intint*

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

++ intintint )) ((

Page 274: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

**intint((((++intintint ))intint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

++ intintint )) ((

Page 275: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

int**intint((((++intintint ))int

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

++ intintint )) ((

Page 276: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

intint**intint((((++intintint ))

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

++ intintint )) ((

Page 277: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

)intint**intint((((++intintint )

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

++ intintint )) ((

Page 278: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

))intint**intint((((++intintint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

++ intintint )) (

Page 279: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

+))intint**intint((((++intintint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

+ intintint )) (

Page 280: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

++))intint**intint((((++intintint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

intintint )) (

Page 281: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

intint++))intint**intint((((++intintint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

int )) (

Page 282: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

intintint++))intint**intint((((++intintint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

)) (

Page 283: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

)intintint++))intint**intint((((++intintint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

) (

Page 284: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

))intintint++))intint**intint((((++intintint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Z0

Page 285: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Z0

))intintint++))intint**intint((((++intintint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Page 286: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

))intintint++))intint**intint((((++intintint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Page 287: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

))intintint++))intint**intint((((++intintint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Page 288: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

))intintint++))intint**intint((((++intintint

A PDA for Arithmetic

int, ε → ε

+, ε → ε*, ε → ε

ε, Z0 → ε

(, ε → ( ), ( → ε

start

Page 289: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Power of PDAs

Page 290: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Classes of Languages

● Recall: A language is regular iff there is a DFA, NFA, or regular expression for it.

● A language is called context-free iff there is a PDA for it.● More on that terminology next time.

● We have seen at least one language (palindromes) that is context-free but not regular.

● How do these classes relate to one another?

Page 291: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Regular and Context-Free Languages

Theorem: Any regular language is context-free.

Proof Sketch: Let L be any regular language and consider a DFA D for L. Then we can convert D into a PDA for L by converting any transition on a symbol a into a transition a, ε → ε that ignores the stack. This new PDA accepts L, so L is context-free. ■-ish

Page 292: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Regular and Context-Free Languages

Theorem: Any regular language is context-free.

Proof Sketch: Let L be any regular language and consider a DFA D for L. Then we can convert D into a PDA for L by converting any transition on a symbol a into a transition a, ε → ε that ignores the stack. This new PDA accepts L, so L is context-free. ■-ish

Page 293: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Regular and Context-Free Languages

Theorem: Any regular language is context-free.

Proof Sketch: Let L be any regular language and consider a DFA D for L. Then we can convert D into a PDA for L by converting any transition on a symbol a into a transition a, ε → ε that ignores the stack. This new PDA accepts L, so L is context-free. ■-ish

Page 294: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Regular and Context-Free Languages

Theorem: Any regular language is context-free.

Proof Sketch: Let L be any regular language and consider a DFA D for L. Then we can convert D into a PDA for L by converting any transition on a symbol a into a transition a, ε → ε that ignores the stack. This new PDA accepts L, so L is context-free. ■-ish

Page 295: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

RegularLanguages CFLs

All Languages

Page 296: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Refining the Context-Free Languages

Page 297: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

NPDAs and DPDAs

● With finite automata, we considered both deterministic (DFAs) and nondeterministic (NFAs) automata.

● So far, we've only seen nondeterministic PDAs (or NPDAs).

● What about deterministic PDAs (DPDAs)?

Page 298: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

DPDAs

● A deterministic pushdown automaton is a PDA with the extra property that

For each state in the PDA, and for any combinationof a current input symbol and a current stack symbol,

there is at most one transition defined.

● In other words, there is at most one legal sequence of transitions that can be followed for any input.

● This does not preclude ε-transitions, as long as there is never a conflict between following the ε-transition or some other transition.

● However, there can be at most one ε-transition that could be followed at any one time.

● This does not preclude the automaton “dying” from having no transitions defined; DPDAs can have undefined transitions.

Page 299: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

DPDAs

A deterministic pushdown automaton is a PDA with the extra property that

For each state in the PDA, and for any combinationof a current input symbol and a current stack symbol,

there is at most one transition defined.

In other words, there is at most one legal sequence of transitions that can be followed for any input.

This does not preclude ε-transitions, as long as there is never a conflict between following the ε-transition or some other transition.

However, there can be at most one ε-transition that could be followed at any one time.

● This does not preclude the automaton “dying” from having no transitions defined; DPDAs can have undefined transitions.

Page 300: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

A deterministic pushdown automaton is a PDA with the extra property that

For each state in the PDA, and for any combinationof a current input symbol and a current stack symbol,

there is at most one transition defined.

In other words, there is at most one legal sequence of transitions that can be followed for any input.

This does not preclude ε-transitions, as long as there is never a conflict between following the ε-transition or some other transition.

However, there can be at most one ε-transition that could be followed at any one time.

● This does not preclude the automaton “dying” from having no transitions defined; DPDAs can have undefined transitions.

DPDAs

Sipser's definition of DPDAs does not allow the machine to “die” in some configuration.

For CS103, we'll allow transitions to be missing.

Sipser's definition of DPDAs does not allow the machine to “die” in some configuration.

For CS103, we'll allow transitions to be missing.

Page 301: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

ε, Z0 → ε

start

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 302: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

ε, Z0 → ε

start

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 303: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

ε, Z0 → ε

start

0, Z0 → 0Z

0

0, 0 → 001, 0 → ε

Page 304: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Page 305: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

This ε-transition is allowable because no other transitions in this

state use the input symbol 0

This ε-transition is allowable because no other transitions in this

state use the input symbol 0

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

This ε-transition is allowable because no other transitions in this state use the stack symbol Z0.

This ε-transition is allowable because no other transitions in this state use the stack symbol Z0.

Page 306: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Page 307: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

0 1 0 0 1 1

Page 308: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 309: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 310: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 311: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 312: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1 0

Page 313: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1 0

Page 314: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1 0

Page 315: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 316: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 317: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 318: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

0 1 0 0 1 1

Page 319: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 320: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 321: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 322: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1 0

Page 323: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1 0

Page 324: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1 0

Page 325: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 326: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1 00

Page 327: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1 00

Page 328: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1 00

Page 329: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1 0

Page 330: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1 0

Page 331: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1 0

Page 332: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 333: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 334: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 335: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

0 1 0 0 1 1

Page 336: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 337: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 338: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 339: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Is this a DPDA?

0, ε → 0

0, 0 → 001, 0 → ε

ε, Z0 → Z

0

start

Z00 1 0 0 1 1

Page 340: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Why DPDAs Matter

● Because DPDAs are deterministic, they can be simulated efficiently:● Keep track of the top of the stack.● Store an action/goto table that says what

operations to perform on the stack and what state to enter on each input/stack pair.

● Loop over the input, processing input/stack pairs until the automaton rejects or ends in an accepting state with all input consumed.

● If we can find a DPDA for a CFL, then we can recognize strings in that language efficiently.

Page 341: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

If we can find a DPDA for a CFL, then we can recognize strings in that language

efficiently.

Can we guarantee that we can always find a DPDA for a CFL?

Page 342: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

The Power of Nondeterminism

● When dealing with finite automata, there is no difference in the power of NFAs and DFAs.

● However, when dealing with PDAs, there are CFLs that can be recognized by NPDAs that cannot be recognized by DPDAs.

● Simple example: The language of palindromes.● How do you know when you've read half the string?

● NPDAs are more powerful than DPDAs.

Page 343: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Deterministic CFLs

● A context-free language L is called a deterministic context-free language (DCFL) if there is some DPDA that recognizes L.

● Not all CFLs are DCFLs, though many important ones are.

● Balanced parentheses, most programming languages, etc.

RegularLanguages CFLs DCFLsWhy are all regular

languages DCFLs?

Why are all regular languages DCFLs?

Page 344: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Separating DCFLs and CFLs

● It is extremely difficult to prove that a given CFL is not a DCFL.

● Challenge problem:

Prove that the language of all palindromes over Σ = {0, 1} is not

deterministic context-free.

Page 345: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Summary

● Automata can be augmented with a memory storage to increase their power.

● PDAs are finite automata equipped with a stack.

● PDAs accept precisely the context-free languages, which are a strict superset of the regular languages.

● Deterministic PDAs are strictly weaker than nondeterministic PDAs.

Page 346: Pushdown Automata - Stanford University...Caution with the Pumping Lemma The weak and full pumping lemmas describe a necessary condition of regular languages. If L is regular, L passes

Next Time

● Context-Free Grammars● A different formalism for context-free

languages.

● The Limits of CFLs● What problems cannot be solved by PDAs?