0% found this document useful (0 votes)
98 views20 pages

CT Lecture 8-PDA

The document discusses pushdown automata (PDA), which can implement context-free grammars. It defines PDA components and transitions, and provides examples of designing PDA for specific languages with acceptance by final state or empty stack.

Uploaded by

Ellie Ng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views20 pages

CT Lecture 8-PDA

The document discusses pushdown automata (PDA), which can implement context-free grammars. It defines PDA components and transitions, and provides examples of designing PDA for specific languages with acceptance by final state or empty stack.

Uploaded by

Ellie Ng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Push Down Automata

Lecture -8

1
Topics

• Push Down Automata

• Examples

• PDA and CFG

Module Code and Module Title Title of Slides


How will you Implement Context
Free Grammar for Compilers?

Module Code and Module Title Title of Slides


Push Down Automata

• PDA can write symbols on the stack(LIFO) and read them


back later .
• Writing a symbol pushes down all the symbols on the stack.
• At any time ,the symbol on the top of the stack can be read.
• Writing is referred as pushing and reading is referred as
popping.
• Stack is referred as “Last In First Out” Storage device.

Module Code and Module Title Title of Slides


PDA

Module Code and Module Title Title of Slides


Push Down Automata
 A pushdown automaton is a way to implement a context-free grammar
in a similar way we design DFA for a regular grammar.
 A DFA can remember a finite amount of information, but a PDA can
remember an infinite amount of information.
Def 8: A push-down automata is a tuple M = (Q, ∑, δ, Γ, q0, F) where:
• (same) Q is a finite set of states
• (same) ∑ is an alphabet
• (new) Γ is the stack alphabet
• (same) q0  Q is the initial state
• (same) F  Q is the set of final states
• (new) δ, the transition relation is a finite subset of

Module Code and Module Title Title of Slides


PDA

"Finite state machine" and "a stack“

(Q x (∑ υ {ε}) x Γ*) (Q x Γ*)

Module Code and Module Title Title of Slides


PDA
• A pushdown automaton has three components −
 an input tape,
 a control unit, and
 a stack with infinite size.
• The stack head scans the top symbol of the stack.
• A stack does two operations −
 Push − a new symbol is added at the top.
 Pop − the top symbol is read and removed.
• A PDA may or may not read an input symbol, but it has to read
the top of the stack in every transition.
Module Code and Module Title Title of Slides
Move Operations in Stack

• String in the tape can be pushed to the stack

• Top element in the stack can be popped

• Top element is replaced by string of stack symbols.

Module Code and Module Title Title of Slides


Steps for PDA

• Number of Push operations should be equal to number of


pop operations.
• All the elements present in the Input tape should be read.
• After completing all the operations the stack should be left
as empty(∈) or with some element (z0 )

Module Code and Module Title Title of Slides


n n
Example –a b

Push a Pop a

a Push a
a Pop a

a Push a a
Pop a
z Top of the stack
z

Module Code and Module Title Title of Slides


Pushdown Automata Acceptance
There are two different ways to define PDA acceptability.

• Final State Acceptability:


 From the starting state, we can make moves that end up in a final state with any stack
values.

• Empty Stack Acceptability


 Stack is empty after reading all the strings.

Module Code and Module Title Title of Slides


Check whether string “aabaa” accepted by
push down automata
Stack
a a b a a a Push ‘a’ when z0
is on the top of
z0 z0 stack

a a b a a a a Push ‘a’ when a


z0 a is on the top of
stack
z0

Module Code and Module Title Title of Slides


Check whether string “aabaa” accepted by
push down automata Stack
a a
Stop Push
a a b a a a
a Operation
z0 Z0

a a Pop ‘a’ when a


is on the top
a a b a a a z0 of stack
z0
Pop ‘a’ when a
a is on the top of
z0 z0 stack
a a b a a
Module Code and Module Title Title of Slides
State Transition table-Final State Acceptability
L = {aabaa}
Input Tape Stack Operation

δ (q0, a, z0 ) q1 , az0 Push

δ (q1,a, a) q1 , aa Push

δ (q1, b, a) q1 , aa Stop push

δ (q1, a, a) q2 , az0 Pop a

δ (q2, a, a ) qf, z0 Pop a


Module Code and Module Title Title of Slides
Example-1(PDA) Final State Acceptability

• PDA for accepting L = { aabaa}


b,a/aa (stop push)
a,a/aa (Push)

(Push)

q0 a,z0/az0 q1 a,a/az0(pop) q2 a,a/z0(pop) qf

Module Code and Module Title Title of Slides


State Transition table-Empty State Acceptability
L = {aabaa} Input Tape Stack Operation

δ (q0, a, ∈ ) q1 , a Push

δ (q1,a, a) q1 , aa Push

δ (q1, b, a) q1 , aa Stop push

δ (q1, a, a) q2 , a Pop a

δ (q2, a, a ) q2, ∈ Pop a

Module Code and Module Title Title of Slides


Example-1(PDA) EmptyState Acceptability

• PDA for accepting L = { aabaa}


b,a/aa (stop push)
a,a/aa (Push) a,a/ ∈ (pop)

(Push)

q0 a, ∈/a q1a,a/a, ∈(pop ) q2

Module Code and Module Title Title of Slides


Try Example (PDA)
• PDA for accepting L = {anbn | n =2}
• PDA for accepting L = {anbncm | n =2 ,m=1}
• PDA for accepting L={aabbaaba}
• PDA for accepting L={aaaabbbb}
• PDA for accepting L={010101011}

Module Code and Module Title Title of Slides


PDA & Context-Free Grammar

Conclusion

• Push automata can be designed with acceptance by final


state

• Push automata can be designed with acceptance by


empty stack.

Module Code and Module Title Title of Slides

You might also like