0% found this document useful (0 votes)
11 views15 pages

Automata Lectuee6

The document provides an overview of Pushdown Automata (PDA), which extends nondeterministic finite automata with a stack to recognize context-free languages. It details the components of a PDA, including states, input alphabet, stack symbols, and the transition function. Examples illustrate how PDAs can be used to recognize specific languages, such as balanced parentheses and palindromes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views15 pages

Automata Lectuee6

The document provides an overview of Pushdown Automata (PDA), which extends nondeterministic finite automata with a stack to recognize context-free languages. It details the components of a PDA, including states, input alphabet, stack symbols, and the transition function. Examples illustrate how PDAs can be used to recognize specific languages, such as balanced parentheses and palindromes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 15

MENOUFIAUNIVERSITY

FACULTYOFCOMPUTERSANDINFORMATION

‫جامعة المنوفية‬

Third Level (Second Semester)


Software Engineering, CS Dept., (CS314)

FORMAL LANGUAGES AND


AUTOMATA THEORY
Lecture Five

Dr. Hamdy M. Mousa

Today Proverb
‫العلم نور‬
Knowledge is power
Pushdown Automata
(PDA)

2
Pushdown Automata (PDA)
Definition:
•PDA is an extension of the nondeterministic finite automaton
with  transition.
• The pushdown automaton can remember an infinite amount of
information.
• FA to Reg Lang
• PDA is the automata for CFLs
PDA == [  -NFA + “a stack” ]
•Why a stack?
• The stack can be read, pushed and popped only at the
top.
Input string -NFA Accept / reject

A stack filled with


“stack symbols”
Pushdown Automata
Definition:
PDA P := ( Q, ∑, , δ, q0, Z0, F )

• Q: states of the -NFA


• ∑: input alphabet
• : stack symbols
• δ: transition function
• q0: start state
• Z 0: Initial stack top symbol
• F: Final/accepting states
The Transition Function (δ)
PDA is allowed to observe the symbol at the top of
the stack and to base its transition
transitio on:
1. its current state the input symbol and
2. the symbol at the top of stack.

old state input symbols Stack top new state(s) new Stack top(s)

δ: Q x ∑ x  => Q x 

•Stack symbol Z0 to mark the bottom of the stack


PUSHDOWN AUTOMATA (PDA)
Non-deterministic PDA
• PDA that recognizes L = { 0n1n | n ≥ 0 }

input pop push

ε, ε → Z0
0011 0. ε → 0

1, 0 → ε

ε, Z0 → ε
1, 0 → ε
• PDA that recognizes L = { 0n1n | n ≥ 0 }

input pop push

ε,ε → Z0
11
001
01 0, ε → 0
11
1, 0 → ε

ε, Z0 → ε
1 1, 0→ ε

$ $
The Transition Function (δ)
old state input symb. Stack top new state(s) new Stack top(s)

δ: Q x ∑ x  => Q x 
δ(q, a, X) = {(p, Y), …}
1. state transition from q to p X Y
a
2. a is the next input symbol q p
3. X is the current stack top
symbol
rminnism
ism

Y=? Action
4. Y is the replacement for X;
it is in * (a string of stack
ddeetteermi

symbols) i) Y= Pop(X)


NNoonn--

i. Set Y =  for: Pop(X) ii) Y=X Pop(X)


ii. If Y = X: stack top is Push(X)
unchanged iii) Y = Z1Z2 … Zk Pop(X)
iii.If Y=Z1 Z2 … Zk: X is Push(Zk)
popped and is replaced by Push(Zk-1)
Y in reverse order (i.e., Z1 …
Push(Z2)
will be the new stack top)
Push(Z1)
Reverse Order
Example
Let: Context Free Grammar for palindromes
Lwwr = {wwR | w is in (0+1)*}

• CFG for Lwwr :S ==> 0S0 | 1S1 | 


• PDA for Lwwr :
P := ( Q, ∑, , δ, q0, Z0, F )
= ( {q0, q1, q2} ,{0,1}, {0,1,Z0}, δ, q0, Z0, {q2})
q0 q1 q2
PDA as a state diagram
δ(qi, a, X)={(qj,Y)}

Next Current Stack Top


input stack Replacement
symbol top (w/ string Y)

Current
state
Next
a, X / Y state
qi qj

Note: Z0  the bottom of the stack


Rules of PDA for Lwwr
1. δ(q0, 0, Z0)={(q0, 0Z0)}
First symbol push on stack Initial state of the PDA:
2. δ(q0, 1, Z0)={(q0, 1Z0)}

3. δ(q0, 0, 0)={(q0, 00)} q0


Grow the stack by pushing Stack
4. δ(q0, 0, 1)={(q0, 01)} Z0
top
5. δ(q0, 1, 0)={(q0, 10)} new symbols on top of old
6. δ(q0, 1, 1)={(q0, 11)} (w-part)
q0 q1 q2
7. δ(q0, , 0)={(q1, 0)}
Switch to popping mode, non-deterministically
8. δ(q0, , 1)={(q1, 1)} (boundary between w and wR)
9. δ(q0, , Z0)={(q1, Z0)}

10. δ(q1,0, 0)={(q1, )}


Shrink the stack by popping matching
symbols (wR-part)
11. δ(q1,1, 1)={(q1, )}

Enter acceptance state


12. δ(q1, , Z0)={(q2, Z0)}
Transition Diagram
• Transition Diagram of PDA for Lwwr
Grow stack ∑ = {0, 1}
 = {Z0, 0, 1}
0, Z0/0Z0
Pop stack for Q = {q0, q1,
1, Z0/1Z0
matching symbols
0, 0/00 q2}
0, 1/01
1, 0/10 0, 0/ 
1, 1/11
1, 1/ 

q0 q1 q2
, Z0/Z0
 , Z 0 / Z0  , Z 0 / Z0
, 0 / 0
, 1 / 1
Go to acceptance
Switch to
popping mode

This would be a non-deterministic PDA


Example
• Language of Balanced Parenthesis
Pop stack for ∑ = { (, ) }
matching symbols  = {Z0, ( }
Grow stack
Q = {q0, q1, q2}
(, Z0 / ( Z0
(, ( / ( ( ), ( / 

q0 q1 q2
, Z0 / Z0 ), ( /  , Z0 / Z0
, Z0 / Z0 Go to acceptance (by final
state) when you see the
(, ( / ( ( stack bottom symbol
Switch to (, Z0 / ( Z0
popping mode
To allow adjacent
blocks of nested
paranthesis
Example
• Another Design of Language of Balanced
Parenthesis.

(,Z0 / ( Z0 ∑ = { (, ) }
 = {Z0, ( }
(,( / ( (
), ( /  Q = {q0, q1}

, Z0/ Z0
start
q0 q1
, Z0/ Z0

You might also like