1 Pushdown Automata Definition: relation to  -NFA Moves of the PDA Languages of the PDA Deterministic PDA’s Quiz Wednesday 11-19-14 on CFGs lecture #3.

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
Pushdown Automata (PDA)
Pushdown Automata Part II: PDAs and CFG Chapter 12.
CS21 Decidability and Tractability
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
1 Pushdown Automata Definition Moves of the PDA Languages of the PDA Deterministic PDA’s.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Prof. Busch - LSU1 Pushdown Automata PDAs. Prof. Busch - LSU2 Pushdown Automaton -- PDA Input String Stack States.
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Pushdown Automata.
Chapter 7 PDA and CFLs.
CS 461 – Sept. 26 CFG correctness Section 2.2 – Pushdown Automata.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s Pushdown Automata 11.
Lecture Pushdown Automata. stack stack head finite control tape head tape.
Push-down Automata Section 3.3 Fri, Oct 21, 2005.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Formal Languages, Automata and Models of Computation
1 Chapter 6 Pushdown automata Sagrada Familia ( 聖家 堂 ), Barcelona, Spain.
1 Pushdown Automata Definition Moves of the PDA Languages of the PDA Deterministic PDA’s.
Lecture 14 Push Down Automata (PDA) Topics:  Definition  Moves of the PDA  Languages of the PDA  Deterministic PDA’s June 18, 2015 CSCE 355 Foundations.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
1.Draw a parse tree for the following derivation: S  C A C  C A b b  b b A b b  b b B b b  b b a A a a b b  b b a b a a b b 2. Show on your parse.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Formal Languages, Automata and Models of Computation
Pushdown Automata.
Lecture 14 Push Down Automata (PDA)
CSE 105 theory of computation
Pushdown Automata (PDA). Part 2
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
AUTOMATA THEORY VI.
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
CSE 105 theory of computation
… NPDAs continued.
Pushdown automata The Chinese University of Hong Kong Fall 2011
CSE 105 theory of computation
Push Down Automata Push Down Automata (PDAs) are L-NFAs with stack memory. Transitions are labeled by an input symbol together with a pair of the form.
CSE 105 theory of computation
Presentation transcript:

1 Pushdown Automata Definition: relation to  -NFA Moves of the PDA Languages of the PDA Deterministic PDA’s Quiz Wednesday on CFGs lecture #3

2 Pushdown Automata uThe PDA is an automaton equivalent to the CFG in language-defining power. uOnly the nondeterministic PDA defines all the CFL’s. uThe deterministic version models parsers. wMost programming languages have deterministic PDA’s.

3 PDA’s related to  -NFA’s  Think of an ε -NFA with the additional power that it can manipulate a stack. uMoves are determined by: 1.The current state of the  -NFA), 2.The current input symbol (or ε ), and 3.The current symbol on top of its stack.

4 PDA’s related to  -NFA’s - 2 uBeing nondeterministic, the PDA can simultaneously explore several moves. uIn each move, the PDA can: 1.Change state and 2.Replace the top symbol on the stack by zero or more symbols. uZero symbols = “pop.” uOne symbol = “push”

5 PDA Formalism uA PDA is described by: 1.A finite set of states (Q, typically). 2.An input alphabet ( Σ, typically). 3.A stack alphabet ( Γ, typically). 4.A transition function ( δ, typically). 5.A start state (q 0, in Q, typically). 6.A start symbol (Z 0, in Γ, typically). 7.A set of final states (F ⊆ Q, typically).

6 Conventions on symbols ua, b, … are input symbols.  ε (empty string) may be used at any point in as a possibility (i.e. a spontaneous transition) u…, X, Y, Z are stack symbols. u…, w, x, y, z are strings of input symbols u , ,… are strings of stack symbols.

7 The Transition Function uTakes three arguments: 1.q is a state in Q 2.a (next input symbol) or ε. 3.Z is top symbol of stack  δ (q, a, Z) is a set of zero or more actions of the form (p,  ) where wp is a state and w  is a string of stack symbols

8 Actions of the PDA  If δ (q, a, Z) contains (p,  ) among its actions, then the PDA could: 1.Change its state to p. 2.Remove a from the front of the input 3.Replace Z on the top of the stack by 

9 Sting acceptance by PDA uDepends on status of input and stack 1.Typically all input consumed. 2.Stack could be empty or in start state

10 Example of PDA uDesign a PDA to accept {0 n 1 n | n > 1}. uThe states: wq = start state and where we are if we have seen only 0’s in the input so far. wp = state after we’ve seen at least one 1 and may proceed only if the inputs are 1’s. wf = accepting state.

11 PDA to accept {0 n 1 n | n > 1} uThe stack symbols: wZ 0 = start symbol. wWhenever Z 0 is top of stack, we have counted the same number of 1’s as 0’s (initially count is zero) wX = marker pushed onto stack every time 0 is the input (i.e. counts the number of 0’s)

12 PDA to accept {0 n 1 n | n > 1} uThe transitions:  (1) δ (q, 0, Z 0 ) = {(q, XZ 0 )}.  (2) δ (q, 0, X) = {(q, XX)}. These two rules cause one X to be pushed onto the stack for each 0 read from the input.  (3) δ (q, 1, X) = {(p, ε )}. When we see a 1, go to state p and pop one X.  (4) δ (p, 1, X) = {(p, ε )}. Pop one X per 1.  (5) δ (p, ε, Z 0 ) = {(f, Z 0 )}. Accept

13 Actions of the Example PDA q Z0Z0

14 Actions of the Example PDA q XZ0XZ0

15 Actions of the Example PDA q XXZ0XXZ0

16 Actions of the Example PDA q XXXZ0XXXZ0

17 Actions of the Example PDA p 1 XXZ0XXZ0

18 Actions of the Example PDA p 1 XZ0XZ0

19 Actions of the Example PDA p Z0Z0

20 Actions of the Example PDA f Z0Z0

21 Instantaneous Descriptions uWe can formalize the pictures just seen with an instantaneous description (ID). uA ID is a triple (q, w,  ), where: 1.q is the current state. 2.w is the remaining input. 3.  is the stack contents, top at the left.

22 The “Goes-To” Relation  To say that ID i can become ID j in one move of the PDA, we write i ⊦ j.  Formally, (q, aw, X  ) ⊦ (p, w,  ) for any w and , if δ (q, a, X) contains (p,  ).  Extend ⊦ to ⊦ *, meaning “zero or more moves,” by:  Basis: i ⊦ *i.  Induction: If i ⊦ *j and j ⊦ k, then i ⊦ *k.

23 Example: Goes-To uUsing transitions defined on slide 12, we decide if string is accept or not by a sequence of IDs. uSuperscript denotes transition used  (q, , Z 0 ) 1 ⊦ (q, 00111, XZ 0 ) 2 ⊦ (q, 0111, XXZ 0 ) 2 ⊦ (q, 111, XXXZ 0 ) 3 ⊦ (p, 11, XXZ 0 ) 4 ⊦ (p, 1, XZ 0 ) 4 ⊦ (p, ε, Z 0 ) 5 ⊦ (f, ε, Z 0 )  Thus, (q, , Z 0 ) ⊦ *(f, ε, Z 0 ). uWhat would happen on input ?

24 Example of PDA again uThe transitions:  (1) δ (q, 0, Z 0 ) = {(q, XZ 0 )}.  (2) δ (q, 0, X) = {(q, XX)}. These two rules cause one X to be pushed onto the stack for each 0 read from the input.  (3) δ (q, 1, X) = {(p, ε )}. When we see a 1, go to state p and pop one X.  (4) δ (p, 1, X) = {(p, ε )}. Pop one X per 1.  (5) δ (p, ε, Z 0 ) = {(f, Z 0 )}. Accept.

25 Answer  (q, , Z 0 ) 1 ⊦ (q, , XZ 0 ) 2 ⊦ (q, 01111, XXZ 0 ) 2 ⊦ (q, 1111, XXXZ 0 ) 3 ⊦ (p, 111, XXZ 0 ) 4 ⊦ (p, 11, XZ 0 ) 4 ⊦ (p, 1, Z 0 ) 5 ⊦ (f, 1, Z 0 ) uNote the last ID has no move. u is not accepted, because the input is not completely consumed. Legal because a PDA can use ε input even if input remains. Dead end Dead end; no  alternative

26 Review: PDA Formalism uA PDA is described by: 1.A finite set of states (Q, typically). 2.An input alphabet ( Σ, typically). 3.A stack alphabet ( Γ, typically). 4.A transition function ( δ, typically). 5.A start state (q 0, in Q, typically). 6.A start symbol (Z 0, in Γ, typically). 7.A set of final states (F ⊆ Q, typically).

27 Ex pp P=({p,q},{0,1},{Z 0,X}, ,q,Z 0,{p, noIP, noSk}) uThe transitions:  (1) δ (q, 0, Z 0 ) = {(q, XZ 0 )}  (2) δ (q, 0, X) = {(q, XX)}  (3) δ (q, 1, X) = {(q, X )}  (4) δ (q, , X) = {(p, ε )}  (5) δ (p, , X) = {(p, ε )}  (6) δ (p, 1, X) = {(p, XX )}  (7) δ (p, 1, Z 0 ) = {(p, ε )} Apply to string 01 Why do both {} and () in definitions of the transition function?

28  (q, 01, Z 0 ) 1 ⊦ (q, 1, XZ 0 ) 3 ⊦ (q, , XZ 0 ) 4 ⊦ (p, , Z 0 ) dead end no way to empty stack  (q, 01, Z 0 ) 1 ⊦ (q, 1, XZ 0 )  ⊦ (p, , Z 0 ) 7 ⊦ (p, ,  ) accepting Ex 6.1.1a p234 input 01

29 CptS 317 Fall 2014 Assignment 12, Due Exercise 6.2.5a text p 242 Number the moves in the transition function Identify which move applies at each step of the trace by a superscript on the ID. Quiz Friday, , PDA lectures 1 and 2

30 Languages of a PDAs uA common way to define the language of a PDA is by final state.  If P is a PDA, then L(P) denotes the set of strings w such that (q 0, w, Z 0 ) ⊦ * (f, ε,  ) for final state f and any . uAcceptance determined by final state of P when all input consumed irrespective of stack content.

31 Languages of PDAs uA PDA with the same properties could define a language by empty stack.  If P is a PDA, then N(P) denotes the set of strings w such that (q 0, w, Z 0 ) ⊦ * (q, ε, ε ) for any state q. uAll input consumed, stack empty, and any state can be accepting

32 Languages of PDAs uThe class of all context-free languages contains both L(P) and N(p) uA language L has a PDA that accepts its strings by final state iff it has another PDA that accepts its strings by empty stack.

33 Restate the theorem 1.If language L has a PDA=P that accepts its strings by final state then it has a PDA=P’ that accepts its strings by empty stack 2.If language L has a PDA=P’ that accepts its strings by empty stack then it has a PDA=P” that accepts its strings by final state.

34 If L(P) then N(P’): Basic idea uConstruct P’ that “simulates” P’s acceptance of strings. uIf P accepts, then P’ empties its stack. uSince stack-state of P is irrelevant to its acceptance of strings, could have the case were P empties its stack without accepting. uP’ most avoid simulating this behavior because strings rejected by P could be accepted by P’

35 If L(P) then N(P’): Basic idea 2 uTo avoid accidentally emptying its stack, P’ uses a special bottom-marker to catch the case where P empties its stack without accepting. uSpecial bottom marker tells P’ to push P’s start symbol onto its stack and go to the start state of P

36 If L(P) then N(P’): Proof uP’ has all the states, symbols, and moves of P, plus: 1.Stack symbol X 0, used to guard the stack bottom against accidental emptying. 2.New start state s and “erase” state e. 3.δ (s, ε, X 0 ) = {(q 0, Z 0 X 0 )}. Gets P’ started. 4.δ (f, ε, Y) = δ (e, ε, Y) = {(e, ε )} for any final state f of P and any stack symbol Y including X 0 (erases stack).

37 If N(P’) then L(P’’) Basic idea uP” simulates P’ acceptance of strings. uP” has a special bottom-marker to catch the situation where P’ has consumed input and emptied its stack. uIf so, P” accepts by going to its final state.

38 If N(P’) then L(P’’) proof uP’’ has all the states, symbols, and moves of P’, plus: 1.Stack symbol X 0, used to guard the stack bottom. 2.New start state s and new final state f. 3.δ (s, ε, X 0 ) = {(q 0, Z 0 X 0 )}. Gets P” started. 4.δ (q, ε, X 0 ) = {(f, ε )} for any state q of P’.

39