You are on page 1of 26

Pushdown automata

A FSA with a stack


• Stack used to store symbols
• The automaton can only see the top of
the stack (one or more symbols.
• The stack is just a string, the 1 2 3 4 ....... i....... n
automaton writes on the end; the
automaton reads the end (suffixes).
• We use a shorthand to make it easier
to understand how the stack is used. sn
• Transitions now depend on what is
being read, the state and the top of sn-1
the stack.
• The automaton does not know ...
whether the stack is empty or not.
s1 s2 ... sk sk+1
• However, at the end of a computation s1
we say that. an automaton accepts a
sting if it ends in a final state, it reads
the whole string, and the stack is
empty.
Operations
• Push(s): push s onto the stack
• Pop(s): if s is at the top of the stack, pop iit
• Ignore(): just ignores the stack
• changeTop(s,t): pop(s) and push(t) (s must be at the top of the stack).
• Skip(s): verifies that is at the top of the stack, without popping
• PushOn(s,t): if s is at the top of the stack, push t onto the stack,
Example. {a b
n n : n>= 0}
a,push(a) b,pop(a)

b,pop(a)
1 2
Example. {anbn : n>= 0}
a,push(a) b,pop(a)

b,pop(a)
1 2
State Stack IInput
1 l aaabbb
1 a aabbb
1 aa abbb
1 aaa bbb
2 aa bb
2 a b
2 l l
Example. {a b
n n : n>= 0}
a,push(a) b,pop(a)

b,pop(a)
1 2
State Stack IInput
1 l aaaabbb
1 a aaabbb
1 aa aabbb
1 aaa abbb
1 aaaa bbb
2 aaa bb
2 aa b
2 a l
Example. {a b
n n : n>= 0}
a,push(a) b,pop(a)

b,pop(a)
1 2
State Stack IInput
1 l aabbb
1 a abbb
1 aa bbb
2 a bb
2 l b
Example. {wcwR : w in {a,b}*}

c, iignore
1 2

a,pop(a)
a,push(a) b,oop(b)
b,push(b)
Example. {wcwR : w in {a,b}*}
c, iignore
1 2

a,pop(a)
a,push(a) b,oop(b) State Stack IInput
b,push(b)
1 l abbcbba
1 a bbcbba
1 ab bcbbz
1 abb cbba
2 abb bba
2 ab ba
2 a a
2 l l
Non Determinism is key!
An automaton that recognizes strings of a’s and b’s. that have an a in
the middle.

a, iignore
1 2

a,pop(1)
a,push(1) b,oop(1)
b,push(1)
Example. {wwR : w in {a,b}*}

l, iignore
1
2

a,pop(a)
a,push(a) b,oop(b)
b,push(b)
Example. {w : w in {a,b}*, w=w }
R

???
1 2

a,pop(a)
a,push(a) b,oop(b)
b,push(b)
Strings of a’s and b’s that have the same
number of a’s and b’s

l,push($) l,pop($)
s q f

a,pushOn(a,a)
a,pushOn($,a)
a,pop(b)
b,pushOn(b,b)
b,pushOn($,b)
b,pop(a)
Strings of a’s and b’s that have the same
number of a’s and b’s

a,push(a)
a,pop(b)
b,push(b)
b,pop(a)

Taking Non Determinism to the nth degree


More examples
{ww: w in {a,b}*} is not context free
But this subset {anbamanbam: m>=0, n>=0} is context free

Note that anbamanbam


= anbam+nbam
= anban+mbam
= anbanambam
anbanambam

l,push($)
b, iignore l,pop($) b, gnore
0 1 3 4
2

a,pop(1) a,pop(1)
a,push(1) a,push(1)
anbanambam With non determinism!

l,push($)
b, iignore b, gnore 4
1
2

a,pop(1) a,pop(2)
a,push(1) a,push(2)
After all the examples…..
Formal Definitions

M=(Q,S,G,qI, F, D)
• Q finite set of. states
• S finiite alphabet
• G finite stack alphabet
• qI Î Q initial state
• F Í Q set. Of final states
• D Í (Q ´ G*´ S*) ´ (Q ´ G*) state transition relation
Transitions
((q,s,r),(q1, t))
If the automaton is in state q, s is at the top of the stack, and r is a prefix of
the input, then read r, pop s, push t, and go to state q1.
Since the stack is a string:
• when we state “s is at the top of the stack” we are stating s is a suffix of
the stack. (l is always a suffix of any string, so when we state l is at the
top of the stack, we are not saying that the stack is empty).
• When we say “push t onto the stack” we are saying. Add t to the end of
the stack (which is a string).

How do these transitions correspond to our functions?


Configurations and Language Accepted
• A configuration is a triplet, (q, r, w), qÎQ, rÎG*, wÎS* where : q is
the current state, r is the whole stack, and w is hat is left to be read.
• Yields in one step
• (q, sr, bw) Þ (q’, sr’, w). if. ((q, r, b),(q, r’ )) Î D.
• Yields in zero or more steps: C Þ* K I:.
• C =K
• There is a confiiguration R such that C Þ R and R Þ* K
• The language recognized by an auotmaton M=(Q,S,G,qI, F, D)
• L(M) = {w| wÎS*, (q, l, w) Þ* (f, sr’, w), fÎF}
Combining Automata: union
Combining Automata: union

...
l ...

qI

l
...
...
M a |b
Combining Automata: concatenation
Combining Automata: concatenation
Combining Automata: closure
Combining Automata: closure

You might also like