Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.

Similar presentations


Presentation on theme: "Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6."— Presentation transcript:

1 Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6

2 PDAs: Pushdown Automata Same as Finite Automata (e.g., NFAs), but with the addition of a stack: On each transition, a stack is manipulated and monitored (operations: push, pop, inspect top, check for empty) Allows the automaton to “count” Definition will need to incorporate stack events When is a string acceptable?

3 PDA definition A pushdown automaton M is a tuple M = (Q, , , , q 0, Z 0, F), where: Q is a set of states  is the input alphabet  is the stack alphabet  : Q   +є    (Q   *)* is the state transition function mapping a (state, symbol, stack symbol) triple to a set of (state, string) pairs q 0 is the start state of M Z 0 is the starting stack symbol (initially on the stack) F  Q is the set of accepting states or final states of M

4 PDA transitions A transition between states q x and q y can be carried out in a PDA when a given next input symbol a is read and a given stack symbol X is on top of the stack When the transition to q y is carried out, the symbol X is replaced with a string w of stack symbols  (q x, a, X) contains the pair (q y, w) How are the stack operations push, pop, inspect top, and check if empty carried out? push Y on input a:  (q x, a, X) -> (q y, YX) pop Y:  (q x, a, X) -> (q y, є) How about inspect top and check if empty?

5 Example L = {a n b n : n >= 0} PDA M = ({q 0,q 1,q 2 }, {a,b}, {Z 0,X}, , q 0, Z 0, {q 2 })  defined (informally) as follows: On input a (from q 0 ) push X onto the stack On input b (from q 0 and q 1 ), pop X and transition to q1 (note: cannot transition if X is not on top of the stack) From q0 and q1, transition to final state q 2 if stack is “empty” (Z 0 is on top)

6 Transition function example  (q 0, a, Z 0 ) = {(q 0, XZ 0 )}  (q 0, a, X) = {(q 0, XX)}  (q 0, b, X) = {(q 1, є)}  (q 1, b, X) = {(q 1, є)}  (q 0, є, Z 0 ) = {(q 2, Z 0 )}  (q 1, є, Z 0 ) = {(q 2, Z 0 )}  (q 0, b, Z 0 ) =  (q 1, b, Z 0 ) =  (q 1, a, X) and many others are all equal to {} push X onto the stack on input a pop X from the stack on input b go to final state if Z 0 is on top

7 PDA diagram q0q0 q2q2 a, Z 0, XZ 0 a, X, XX q1q1 b, X, є є, Z 0, Z 0

8 Alternative diagram q0q0 q2q2 a, push X q1q1 b, pop X є, empty b, pop X

9 Accepting strings in a PDA By final state, just like in regular final automata Or by empty stack: string is acceptable once the stack is empty (Z 0 has been popped out), regardless of what state it is currently in These two “kinds” of PDAs are equivalent (proofs in section 6.2)

10 Equivalence between PDAs From PDA-by final state to PDA-by empty stack Add a state that empties the contents of the stack (one epsilon-transition back to itself that pops out any element) From each final state in the PDA add an epsilon-transition to this new state From PDA-by empty stack to PDA-by final state Add a separate final state For each transition that pops out Z 0, update it so that it transitions to the final state instead

11 Equivalence of PDAs and CFGs PDAs and CFGs describe the same set of languages (section 6.3) Proof requires: Construction from a grammar to an equivalent PDA Construction from a PDA to an equivalent grammar (this is harder: will not be covered in this course)

12 From CFG to PDA Given G = (V,T,P,S) Construct PDA M = ({q 0 }, T, V  T, , q 0, S, {}) Single-state PDA Input alphabet: terminal symbols in G Stack alphabet: terminals and non-terminals Starting stack symbol: S  is defined in terms of P

13 From CFG to PDA, continued  is defined as follows For each production N -> w in P: add (q 0, w) to  (q0, є, N) For each terminal symbol a:  (q0, a, a) = {(q 0, є)} The derivation of a string in G is simulated by input processing and stack operations in M

14 Equivalences PDA-by final statePDA-by empty stack Context free grammar All three models describe context free languages (CFLs)


Download ppt "Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6."

Similar presentations


Ads by Google