Download presentation
Presentation is loading. Please wait.
1
1 Lecture 30 Pushdown Automata (PDA’s) –definition –example
2
2 Pushdown Automata Definition and Motivating Example
3
3 PDA’s In this presentation we introduce the PDA model of computation (programming language). –We first begin with an example NFA –We augment this NFA with external memory in the form of a counter –We then transform the counter into a stack to produce a PDA We define configurations and computations of these new computational models We define L(M) for these new computational models
4
4 NFA for {a m b n | m,n >= 0} What strings end up in each state of the above NFA? –A: The set of strings in a*. –B: The set of strings in a*b*. –C: The set of strings in a*b*. Consider the language {a n b n | n >= 0}. This NFA can recognize strings which have the correct form, –a’s followed by b’s. However, the NFA cannot remember the relative number of a’s and b’s seen at any point in time. /\ a b ABC
5
5 NFA + for {a n b n | n >=0 } /\ a b ABC NFA a;add 1 ABC b;substract 1 /\ /\;only if count 0 Initialize count 0 NFA + Imagine we now have memory in the form of a counter which we can increment or decrement every time we see an input character. When we see an a in state A, we do the following two actions: 1) We increment the counter value by 1. 2) We stay in state A. When we see a b in state B, we do the following two actions: 1) We decrement the counter value by 1. 2) We stay in state B. From state B, we allow a /\-transition to state C only if 1) The counter has value 0. Finally, when we begin, the counter should have value 0.
6
6 Defining Configurations of NFA + a;add 1 ABC b;substract 1 /\ /\;only if count 0 Initialize count 0 NFA + The following information needs to be recorded in a configuration of a computation of an NFA + M on an input string x. 1) Current state 2) Remaining input to be processed 3) Current counter value Note, the counter is NOT part of the input. It is part of the computational model. Its current value needs to be recorded in a configuration.
7
7 Computation Tree of NFA + a;add 1 ABC b;substract 1 /\ /\;only if count 0 Initialize count 0 NFA + Computation Tree for this NFA + on the input string aabb (A,aabb,0) (C,aabb,0)(B,bb,2) (B,abb,1)(A,bb,2)(B,aabb,0) (A,abb,1) (B,b,1)(B,/\,0) (C,/\,0)
8
8 Questions about NFA + a;add 1 ABC b;substract 1 /\ /\;only if count 0 Initialize count 0 NFA + 1) Why can this NFA + accept {a n b n | n >= 0}? That is, how do we get around the Myhill-Nerode Theorem? 2) What happens if the counter has a finite capacity? For example, it can only go up to 10. Can some NFA + still accept {a n b n | n >= 0}? 3) Suppose that we have a stack data structure instead of a counter. Can we do anything we could with the counter? Can we do something we could not do with only a counter?
9
9 PDA for {a n b n | n >= 0} a;add 1 ABC b;substract 1 /\ /\;only if count 0 Initialize count 0 NFA + Here is a pushdown automaton (PDA) for this language. A PDA is essentially an NFA augmented with an infinite capacity stack. The “pushdown” part of the name supposedly comes from the stacks trays in cafeterias where you have to pushdown on the stack to add a tray to it. In this example, only one character a is ever pushed onto the stack. ABC b;popa;push a /\;only if stack is empty PDA /\ Initialize stack to empty
10
10 Defining Configurations of PDA The following information needs to be recorded in a configuration of a computation of an PDA M on an input string x. 1) Current state 2) Remaining input to be processed 3) Current stack contents. Note again, the stack is NOT part of the input. It is part of the computational model. However, its current value needs to be recorded in a configuration. We will represent the stack contents by a string of characters. The leftmost character is on top of the stack. The rightmost character is at the bottom of the stack. We will represent an empty stack with the string /\. ABC b;popa;push a /\;only if stack is empty PDA /\ Initialize stack to empty
11
11 Computation Tree of PDA Computation Tree for this PDA on the input string aabb (A,aabb,/\) (C,aabb,/\) (B,bb,aa) (B,abb,a)(A,bb,aa)(B,aabb,/\) (A,abb,a) (B,b,a)(B,/\,/\) (C,/\,/\) ABC b;popa;push a /\;only if stack is empty PDA /\ Initialize stack to empty
12
12 PDA for {a n b n | n >= 0} 1) The first black character is the current input symbol. We allow this to be which is different from the book. 2) The second red character is the current top stack symbol. 3) The third string of characters is the stack update action. 4) The book also includes a tapehead movement action We omit this as weinclude in field 1. The stack character Z is a special character which we will always keep on the bottom of the stack. Note it is part of , though, so it may be used other places as well. ABC b;popa;push a /\;only if stack is empty PDA /\ Initialize stack to empty ABC b;a;pop a;a;push a a;Z; push a /\;Z;- /\;a;- /\;Z;- Our actual PDA Initialize stack to empty (only contains Z)
13
13 Computation Tree of PDA Computation Tree for this PDA on the input string aabb (A,aabb,Z) (C,aabb,Z) (B,bb,aaZ) (B,abb,aZ)(A,bb,aaZ) (A,abb,aZ) (B,aabb,Z) (B,b,aZ)(B,/\,Z) (C,/\,Z) ABC b;a;pop a;a;push a a;Z; push a /\;Z;- /\;a;- /\;Z;- Our actual PDA Initialize stack to empty (only contains Z)
14
14 Formal Definition of PDA A PDA M = (Q, , , q 0, Z, A, ) Items common to NFAs Q is the set of states is the input alphabet q 0 is the initial state A is the set of accepting states Modified items is the stack alphabet - Z is a special character in - The stack always begins containing 1 Z : modified as follows: pops/reads top stack symbol as well as current input character describes how to update stack note push /\ results in pop! Q = {I, B, C} = {a,b} = {Z, a} q 0 = I Z is the initial stack character A = {C} :: stateinputtop stacknext statestack update IaaIpush aa IaZIpush aZ I/\aBpush a I/\ZBpush Z BbaBpush /\ B/\ZCpush Z IBC b;a;/\ a;a; aa a;Z; aZ /\;Z;Z /\;a;a /\;Z;Z Our actual PDA Initialize stack to empty (only contains Z)
15
15 L(M) for a PDA Computation Tree for this PDA on the input string aabb (A,aabb, ) (A,abb,a) (B,aabb, ) (C,aabb, ) (B,abb,a)(A,bb,aaZ) (B,bb,aa) (B,b,a) (B,, ) (C ) A string x is in L(M) if and only if it there exists an accepting configuration (q, /\, anything) in the computation tree of M on x. An accepting configuration satisfies the following two conditions : 1) The PDA must be in an accepting state 2) The input string must be completely processed Note, the stack contents is unimportant. This is known as acceptance by final state. An accepting configuration. Not an accepting configuration because the remaining input string is not /\. Not an accepting configuration because the state B is not an accepting state. ABC b;a;- a;a;aa a;Z;aZ /\;Z;Z /\;a;a /\;Z;Z Our actual PDA Initialize stack to empty (only contains Z)
16
16 PDA Comments Note, we can use the stack for much more than just a counter See examples in section 6.1 for some details
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.