A Finite Automaton

Transcription

A Finite Automaton
A Finite Automaton
011011001
read
unread
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.1
A Pushdown Automaton
0110110
read
unread
a
b
b
a
pop
push
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.2
A Pushdown Automaton
can push symbols onto the stack
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.3
A Pushdown Automaton
can push symbols onto the stack
can pop them (read them back) later
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.3
A Pushdown Automaton
can push symbols onto the stack
can pop them (read them back) later
stack can grow unboundedly
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.3
A Pushdown Automaton
can push symbols onto the stack
can pop them (read them back) later
stack can grow unboundedly
yet at any moment stack has finite size.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.3
An Example
Recall that the language {0n 1n | n ≥ 0} is not regular.
Consider the following PDA:
read input symbols
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.4
An Example
Recall that the language {0n 1n | n ≥ 0} is not regular.
Consider the following PDA:
read input symbols
for each 0, push it on the stack
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.4
An Example
Recall that the language {0n 1n | n ≥ 0} is not regular.
Consider the following PDA:
read input symbols
for each 0, push it on the stack
as soon as a 1 is seen, pop a 0 for each 1 read
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.4
An Example
Recall that the language {0n 1n | n ≥ 0} is not regular.
Consider the following PDA:
read input symbols
for each 0, push it on the stack
as soon as a 1 is seen, pop a 0 for each 1 read
accept if stack is empty when last symbol read
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.4
An Example
Recall that the language {0n 1n | n ≥ 0} is not regular.
Consider the following PDA:
read input symbols
for each 0, push it on the stack
as soon as a 1 is seen, pop a 0 for each 1 read
accept if stack is empty when last symbol read
reject if
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.4
An Example
Recall that the language {0n 1n | n ≥ 0} is not regular.
Consider the following PDA:
read input symbols
for each 0, push it on the stack
as soon as a 1 is seen, pop a 0 for each 1 read
accept if stack is empty when last symbol read
reject if
stack is non-empty when last symbol read
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.4
An Example
Recall that the language {0n 1n | n ≥ 0} is not regular.
Consider the following PDA:
read input symbols
for each 0, push it on the stack
as soon as a 1 is seen, pop a 0 for each 1 read
accept if stack is empty when last symbol read
reject if
stack is non-empty when last symbol read
stack is empty but input symbol(s) still exist,
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.4
An Example
Recall that the language {0n 1n | n ≥ 0} is not regular.
Consider the following PDA:
read input symbols
for each 0, push it on the stack
as soon as a 1 is seen, pop a 0 for each 1 read
accept if stack is empty when last symbol read
reject if
stack is non-empty when last symbol read
stack is empty but input symbol(s) still exist,
0 is read after 1.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.4
On PDA vs. Finite Automata
Nondeterminism
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.5
On PDA vs. Finite Automata
Nondeterminism
PDA may be deterministic or
non-deterministic.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.5
On PDA vs. Finite Automata
Nondeterminism
PDA may be deterministic or
non-deterministic.
Unlike finite automata, non-determinism adds
power.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.5
On PDA vs. Finite Automata
Nondeterminism
PDA may be deterministic or
non-deterministic.
Unlike finite automata, non-determinism adds
power.
There are some languages accepted only by
non-deterministic PDAs.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.5
On PDA vs. Finite Automata
Nondeterminism
PDA may be deterministic or
non-deterministic.
Unlike finite automata, non-determinism adds
power.
There are some languages accepted only by
non-deterministic PDAs.
Transition function δ looks different than DFA or
NFA cases, reflecting stack functionality.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.5
The Transition Function
Denote input alphabet by Σ and stack alphabet by Γ.
the domain of the transition function δ is
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.6
The Transition Function
Denote input alphabet by Σ and stack alphabet by Γ.
the domain of the transition function δ is
current state: Q
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.6
The Transition Function
Denote input alphabet by Σ and stack alphabet by Γ.
the domain of the transition function δ is
current state: Q
next input symbol, if any: Σε (=Σ ∪ {ε})
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.6
The Transition Function
Denote input alphabet by Σ and stack alphabet by Γ.
the domain of the transition function δ is
current state: Q
next input symbol, if any: Σε (=Σ ∪ {ε})
stack symbol popped, if any: Γε
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.6
The Transition Function
Denote input alphabet by Σ and stack alphabet by Γ.
the domain of the transition function δ is
current state: Q
next input symbol, if any: Σε (=Σ ∪ {ε})
stack symbol popped, if any: Γε
and its range is
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.6
The Transition Function
Denote input alphabet by Σ and stack alphabet by Γ.
the domain of the transition function δ is
current state: Q
next input symbol, if any: Σε (=Σ ∪ {ε})
stack symbol popped, if any: Γε
and its range is
new state: Q
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.6
The Transition Function
Denote input alphabet by Σ and stack alphabet by Γ.
the domain of the transition function δ is
current state: Q
next input symbol, if any: Σε (=Σ ∪ {ε})
stack symbol popped, if any: Γε
and its range is
new state: Q
stack symbol pushed, if any: Γε
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.6
The Transition Function
Denote input alphabet by Σ and stack alphabet by Γ.
the domain of the transition function δ is
current state: Q
next input symbol, if any: Σε (=Σ ∪ {ε})
stack symbol popped, if any: Γε
and its range is
new state: Q
stack symbol pushed, if any: Γε
non-determinism: P(· · · )
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.6
The Transition Function
Denote input alphabet by Σ and stack alphabet by Γ.
the domain of the transition function δ is
current state: Q
next input symbol, if any: Σε (=Σ ∪ {ε})
stack symbol popped, if any: Γε
and its range is
new state: Q
stack symbol pushed, if any: Γε
non-determinism: P(· · · )
δ : Q × Σε × Γε → P(Q × Γε )
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.6
Formal Definitions
A pushdown automaton (PDA) is a 6-tuple
(Q, Σ, Γ, δ, q0 , F ), where
Q is a finite set called the states,
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.7
Formal Definitions
A pushdown automaton (PDA) is a 6-tuple
(Q, Σ, Γ, δ, q0 , F ), where
Q is a finite set called the states,
Σ is a finite set called the input alphabet,
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.7
Formal Definitions
A pushdown automaton (PDA) is a 6-tuple
(Q, Σ, Γ, δ, q0 , F ), where
Q is a finite set called the states,
Σ is a finite set called the input alphabet,
Γ is a finite set called the stack alphabet,
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.7
Formal Definitions
A pushdown automaton (PDA) is a 6-tuple
(Q, Σ, Γ, δ, q0 , F ), where
Q is a finite set called the states,
Σ is a finite set called the input alphabet,
Γ is a finite set called the stack alphabet,
δ : Q × Σε × Γε → P(Q × Γε ) is the
transition function,
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.7
Formal Definitions
A pushdown automaton (PDA) is a 6-tuple
(Q, Σ, Γ, δ, q0 , F ), where
Q is a finite set called the states,
Σ is a finite set called the input alphabet,
Γ is a finite set called the stack alphabet,
δ : Q × Σε × Γε → P(Q × Γε ) is the
transition function,
q0 ∈ Q is the start state, and
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.7
Formal Definitions
A pushdown automaton (PDA) is a 6-tuple
(Q, Σ, Γ, δ, q0 , F ), where
Q is a finite set called the states,
Σ is a finite set called the input alphabet,
Γ is a finite set called the stack alphabet,
δ : Q × Σε × Γε → P(Q × Γε ) is the
transition function,
q0 ∈ Q is the start state, and
F ⊆ Q is the set of accept states.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.7
Conventions
Question: When is the stack empty?
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.8
Conventions
Question: When is the stack empty?
start by pushing $ onto stack
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.8
Conventions
Question: When is the stack empty?
start by pushing $ onto stack
when you see it again, stack is empty.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.8
Conventions
Question: When is the stack empty?
start by pushing $ onto stack
when you see it again, stack is empty.
Question: When is input string exhausted?
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.8
Conventions
Question: When is the stack empty?
start by pushing $ onto stack
when you see it again, stack is empty.
Question: When is input string exhausted?
doesn’t matter – PDA need not know this
explicitly
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.8
Conventions
Question: When is the stack empty?
start by pushing $ onto stack
when you see it again, stack is empty.
Question: When is input string exhausted?
doesn’t matter – PDA need not know this
explicitly
accepting state accepts only if inputs
exhausted!
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.8
Notation
Transition a, b → c means
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.9
Notation
Transition a, b → c means
read a from input
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.9
Notation
Transition a, b → c means
read a from input
pop b from stack
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.9
Notation
Transition a, b → c means
read a from input
pop b from stack
push c onto stack
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.9
Notation
Transition a, b → c means
read a from input
pop b from stack
push c onto stack
Meaning of ε transitions:
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.9
Notation
Transition a, b → c means
read a from input
pop b from stack
push c onto stack
Meaning of ε transitions:
if a = ε, don’t read inputs
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.9
Notation
Transition a, b → c means
read a from input
pop b from stack
push c onto stack
Meaning of ε transitions:
if a = ε, don’t read inputs
if b = ε, don’t pop any symbols
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.9
Notation
Transition a, b → c means
read a from input
pop b from stack
push c onto stack
Meaning of ε transitions:
if a = ε, don’t read inputs
if b = ε, don’t pop any symbols
if c = ε, don’t push any symbols
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.9
Example
q1
ε,ε $
q2
1,0
q4
ε,$ ε
q3
0,ε $
ε
1,0
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
ε
– p.10
Example
q1
ε,ε $
q2
1,0
q4
ε,$ ε
q3
0,ε $
ε
1,0
ε
What does this PDA accept?
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.10
Example
q1
ε,ε $
q2
1,0
q4
ε,$ ε
q3
0,ε $
ε
1,0
ε
What does this PDA accept?
{0n 1n |n ≥ 1}.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.10
Another Example
A PDA that accepts
i j k
a b c |i, j, k > 0 and i = j or i = k
Informally:
read and push a’s
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.11
Another Example
A PDA that accepts
i j k
a b c |i, j, k > 0 and i = j or i = k
Informally:
read and push a’s
either pop and match with b’s
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.11
Another Example
A PDA that accepts
i j k
a b c |i, j, k > 0 and i = j or i = k
Informally:
read and push a’s
either pop and match with b’s
or else pop and match with c’s
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.11
Another Example
A PDA that accepts
i j k
a b c |i, j, k > 0 and i = j or i = k
Informally:
read and push a’s
either pop and match with b’s
or else pop and match with c’s
non-deterministic choice!
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.11
Another Example
A PDA that accepts
i j k
a b c |i, j, k > 0 and i = j or i = k
Informally:
read and push a’s
either pop and match with b’s
or else pop and match with c’s
non-deterministic choice!
Note: non-determinism essential here!
Unlike finite automata, non-determinism
does add power
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.11
Another Example
c,ε ε
ε,$ ε
q3
q4
b,a ε
ε,ε $
ε,ε
ε
q1
ε
ε
ε
q5 ε,ε
q2 ε,ε
q0 ε,ε
q7
a,ε a
b,ε ε
c,a ε
This PDA accepts
i j k
a b c |i, j, k > 0 and i = j or i = k
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.12
Yet Another Example
A palindrome is a string w satisfying w = w R.
“Madam I’m Adam”
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.13
Yet Another Example
A palindrome is a string w satisfying w = w R.
“Madam I’m Adam”
“Dennis and Edna sinned”
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.13
Yet Another Example
A palindrome is a string w satisfying w = w R.
“Madam I’m Adam”
“Dennis and Edna sinned”
“Red rum, sir, is murder”
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.13
Yet Another Example
A palindrome is a string w satisfying w = w R.
“Madam I’m Adam”
“Dennis and Edna sinned”
“Red rum, sir, is murder”
“Able was I ere I saw Elba”
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.13
Yet Another Example
A palindrome is a string w satisfying w = w R.
“Madam I’m Adam”
“Dennis and Edna sinned”
“Red rum, sir, is murder”
“Able was I ere I saw Elba”
“In girum imus nocte et consumimur igni”
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.13
Yet Another Example
A palindrome is a string w satisfying w = w R.
“Madam I’m Adam”
“Dennis and Edna sinned”
“Red rum, sir, is murder”
“Able was I ere I saw Elba”
“In girum imus nocte et consumimur igni”
“νιψoν ανoµηµατ α µη µoναν oψιν”
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.13
Yet Another Example
A palindrome is a string w satisfying w = w R.
“Madam I’m Adam”
“Dennis and Edna sinned”
“Red rum, sir, is murder”
“Able was I ere I saw Elba”
“In girum imus nocte et consumimur igni”
“νιψoν ανoµηµατ α µη µoναν oψιν”
Palindromes also appear in nature. For example as
DNA sites (strings over {A, C, T, G}) being cut
by restriction enzymes.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.13
Yet Another Example
q1
ε,ε $
q2
0,ε 0
1,ε 1
ε,ε ε
q4
ε,$ ε
q3
0,0 ε
1,1 ε
This PDA accepts binary palindromes of even length.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.14
Equivalence Theorem
Theorem: A language is context free if and only if
some pushdown automata accepts it.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.15
Equivalence Theorem
Theorem: A language is context free if and only if
some pushdown automata accepts it.
This time, the proofs of both the “if” part and the “only
if” part are interesting.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.15
If Part
Theorem: If a language is context free, then some
pushdown automaton accepts it.
Let A be a context-free language.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.16
If Part
Theorem: If a language is context free, then some
pushdown automaton accepts it.
Let A be a context-free language.
By definition, A has a context-free grammar G
generating it.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.16
If Part
Theorem: If a language is context free, then some
pushdown automaton accepts it.
Let A be a context-free language.
By definition, A has a context-free grammar G
generating it.
On input w, the PDA P should figure out if there
is a derivation of w using G.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.16
If Part
Theorem: If a language is context free, then some
pushdown automaton accepts it.
Let A be a context-free language.
By definition, A has a context-free grammar G
generating it.
On input w, the PDA P should figure out if there
is a derivation of w using G.
Question: How does P figure out which substitution
to make?
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.16
If Part
Theorem: If a language is context free, then some
pushdown automaton accepts it.
Let A be a context-free language.
By definition, A has a context-free grammar G
generating it.
On input w, the PDA P should figure out if there
is a derivation of w using G.
Question: How does P figure out which substitution
to make?
Answer: It guesses.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.16
CFL Implies PDA
Informally:
P pushes start variable S on stack
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.17
CFL Implies PDA
Informally:
P pushes start variable S on stack
keeps making substitutions, storing intermediate
strings
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.17
CFL Implies PDA
Informally:
P pushes start variable S on stack
keeps making substitutions, storing intermediate
strings
when only terminals remain . . .
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.17
CFL Implies PDA
Informally:
P pushes start variable S on stack
keeps making substitutions, storing intermediate
strings
when only terminals remain . . .
tests whether derived string equals input
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.17
CFL Implies PDA
Where do we keep the intermediate string?
Can’t put it all on the stack
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.18
CFL Implies PDA
Where do we keep the intermediate string?
Can’t put it all on the stack
Keep on stack only symbols after first variable
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.18
CFL Implies PDA
Where do we keep the intermediate string?
Can’t put it all on the stack
Keep on stack only symbols after first variable
Terminal symbols before first variable matched
immediately to input string symbols.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.18
CFL Implies PDA
Where do we keep the intermediate string?
Can’t put it all on the stack
Keep on stack only symbols after first variable
Terminal symbols before first variable matched
immediately to input string symbols.
011001
read
unread
A
1
A
0
$
pop
push
intermediate string: 01A1A0
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.18
CFL Implies PDA
Informal description:
push S$ on stack
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.19
CFL Implies PDA
Informal description:
push S$ on stack
if top of stack is a variable A,
non-deterministically select rule and substitute.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.19
CFL Implies PDA
Informal description:
push S$ on stack
if top of stack is a variable A,
non-deterministically select rule and substitute.
if top of stack is terminal a read next input and
compare. If they differ, reject on this branch of
the nondeterminism.
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.19
CFL Implies PDA
Informal description:
push S$ on stack
if top of stack is a variable A,
non-deterministically select rule and substitute.
if top of stack is terminal a read next input and
compare. If they differ, reject on this branch of
the nondeterminism.
if top of stack is $, enter accept state (here we
accept only if input has all been read, as accept
state will have no exits labeled with input
symbols!).
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.19
CFL Implies PDA
Need shorthand to push entire string onto stack (in
this example the pushed string is w = xyz).
(r, w) ∈ δ(q, a, s)
Easy to do by introducing intermediate states.
a,s
q
q
a,s
r
z
ε,ε
xyz
y
r
ε,ε
x
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.20
CFL Implies PDA
States of P are
start state, qs
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.21
CFL Implies PDA
States of P are
start state, qs
accept state, qa
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.21
CFL Implies PDA
States of P are
start state, qs
accept state, qa
loop state, q`
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.21
CFL Implies PDA
States of P are
start state, qs
accept state, qa
loop state, q`
E states, shorthand for pushing entire strings
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.21
Transition Function
Initialize stack – δ(qs , ε, ε) = {q` , S$}
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.22
Transition Function
Initialize stack – δ(qs , ε, ε) = {q` , S$}
Top of stack is variable –
δ(q` , ε, A) = {(q` , w)| where A → w is a rule }
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.22
Transition Function
Initialize stack – δ(qs , ε, ε) = {q` , S$}
Top of stack is variable –
δ(q` , ε, A) = {(q` , w)| where A → w is a rule }
Top of stack is terminal – δ(q` , a, a) = {(q` , ε)}
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.22
Transition Function
Initialize stack – δ(qs , ε, ε) = {q` , S$}
Top of stack is variable –
δ(q` , ε, A) = {(q` , w)| where A → w is a rule }
Top of stack is terminal – δ(q` , a, a) = {(q` , ε)}
End of Stack – δ(q` , ε, $) = {(qa , ε)}
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.22
Transition Function
qs
ε,ε S$
ε,A w
a,a ε
ql
ε,$ ε
qa
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.23
Example
S → aT b|b
T → T a|ε
Initialization:
qs
ε,ε S$
ql
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.24
Example
S → aT b|b
T → T a|ε
Rules for S
ε,ε T
qs
ε,ε S$
ε,S
b
ε,S
b
ε,ε a
ql
qa
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.25
Example
S → aT b|b
T → T a|ε
Rules for T
ε,ε T
qs
ε,ε S$
ε,S
ε,T
b
ε
ε,S
b
ε,T
a
ε,ε a
ql
ε,ε a
qa
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.26
Example
S → aT b|b
T → T a|ε
Rules for terminals
ε,ε T
qs
ε,ε S$
ε,S b
ε,T ε
aa ε
bb ε
ε,S
b
ε,T
a
ε,ε a
ql
ε,ε a
qa
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.27
Example
S → aT b|b
T → T a|ε
Termination:
ε,ε T
qs
ε,ε S$
ε,S
ε,T
aa
bb
b
ε
ε
ε
ε,$
ε,S
b
ε,T
a
ε,ε a
ql
ε
ε,ε a
qa
Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University.
– p.28

Similar documents