1 Pushdown Automata Definition Moves of the PDA Languages of the PDA Deterministic PDA’s.

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
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)
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.
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.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
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.
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
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.
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.
Push-down Automata Section 3.3 Fri, Oct 21, 2005.
1 Pushdown Automata Definition: relation to  -NFA Moves of the PDA Languages of the PDA Deterministic PDA’s Quiz Wednesday on CFGs lecture #3.
PushDown Automata. What is a stack? A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack.
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.
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.
Lecture 16b Turing Machines Topics: Closure Properties of Context Free Languages Cocke-Younger-Kasimi Parsing Algorithm June 23, 2015 CSCE 355 Foundations.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
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.
CS 154 Formal Languages and Computability March 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Pushdown Automata - like NFA-  but also has a stack - transition takes the current state, the current input symbol, and the top-of-the-stack symbol (which.
CSCI 2670 Introduction to Theory of Computing September 22, 2004.
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)
Non Deterministic Automata
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.
Pushdown Automata PDAs
Pushdown Automata.
CSE322 Definition and description of finite Automata
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
… NPDAs continued.
Pushdown automata The Chinese University of Hong Kong Fall 2011
CSE 105 theory of computation
Non Deterministic Automata
CSE 105 theory of computation
Presentation transcript:

1 Pushdown Automata Definition Moves of the PDA Languages of the PDA Deterministic PDA’s

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. uBut the deterministic version models parsers. wMost programming languages have deterministic PDA’s.

3 Intuition: PDA  Think of an ε -NFA with the additional power that it can manipulate a stack. uIts moves are determined by: 1.The current state (of its “NFA”), 2.The current input symbol (or ε ), and 3.The current symbol on top of its stack.

4 Picture of a PDA q XYZXYZ State Stack Top of Stack Input Next input symbol

5 Pushdown Automaton -- PDA Input String Stack -(lifo) States

6 Initial Stack Symbol Stack bottomspecial symbol stack head top Appears at time 0

7 Intuition: PDA – (2) uBeing nondeterministic, the PDA can have a choice of next moves. uIn each choice, the PDA can: 1.Change state, and also 2.Replace the top symbol on the stack by a sequence of zero or more symbols. uZero symbols = “pop.” uMany symbols = sequence of “pushes.”

8 The States Input symbol Pop symbol Push symbol

9 top input stack Replace

10 Push top input stack

11 Pop top input stack

12 No Change top input stack

13 Pop top input stack Pop from Empty Stack Automaton halts! If the automaton attempts to pop from empty stack then it halts and rejects input

14 Non-Determinism PDAs are non-deterministic Allowed non-deterministic transitions

15 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).

16 Conventions ua, b, … are input symbols.  But sometimes we allow ε as a possible value. u…, X, Y, Z are stack symbols. u…, w, x, y, z are strings of input symbols. u , ,… are strings of stack symbols.

17 The Transition Function uTakes three arguments: 1.A state, in Q. 2.An input, which is either a symbol in Σ or ε. 3.A stack symbol in Γ.  δ (q, a, Z) is a set of zero or more actions of the form (p,  ). wp is a state;  is a string of stack symbols.

18 Actions of the PDA  If δ (q, a, Z) contains (p,  ) among its actions, then one thing the PDA can do in state q, with a at the front of the input, and Z on top of the stack is: 1.Change the state to p. 2.Remove a from the front of the input (but a may be ε ). 3.Replace Z on the top of the stack by .

19 Example: PDA uDesign a PDA to accept {0 n 1 n | n > 1}. uThe states: wq = start state. We are in state q if we have seen only 0’s so far. wp = we’ve seen at least one 1 and may now proceed only if the inputs are 1’s. wf = final state; accept.

20 Example: PDA – (2) uThe stack symbols: wZ 0 = start symbol. Also marks the bottom of the stack, so we know when we have counted the same number of 1’s as 0’s. wX = marker, used to count the number of 0’s seen on the input.

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

22 Actions of the Example PDA q Z0Z0

23 Actions of the Example PDA q XZ0XZ0

24 Actions of the Example PDA q XXZ0XXZ0

25 Actions of the Example PDA q XXXZ0XXXZ0

26 Actions of the Example PDA p 1 XXZ0XXZ0

27 Actions of the Example PDA p 1 XZ0XZ0

28 Actions of the Example PDA p Z0Z0

29 Actions of the Example PDA f Z0Z0

30 Example PDA PDA :

31 Basic Idea: 1.Push the a’s on the stack 2. Match the b’s on input with a’s on stack 3. Match found

32 Input Time 1 Stack

33 Input Stack Time 2

34 Input Stack Time 3

35 Input Stack Time 4

36 Input Stack Time 5

37 Input Stack Time 6

38 Input Stack Time 7

Input Time 8 Stack accept

40 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.

41 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.

42 Example: Goes-To  Using the previous example PDA, we can describe the sequence of moves by: (q, , Z 0 ) ⊦ (q, 00111, XZ 0 ) ⊦ (q, 0111, XXZ 0 ) ⊦ (q, 111, XXXZ 0 ) ⊦ (p, 11, XXZ 0 ) ⊦ (p, 1, XZ 0 ) ⊦ (p, ε, Z 0 ) ⊦ (f, ε, Z 0 )  Thus, (q, , Z 0 ) ⊦ *(f, ε, Z 0 ). uWhat would happen on input ?

43 Answer  (q, , Z 0 ) ⊦ (q, , XZ 0 ) ⊦ (q, 01111, XXZ 0 ) ⊦ (q, 1111, XXXZ 0 ) ⊦ (p, 111, XXZ 0 ) ⊦ (p, 11, XZ 0 ) ⊦ (p, 1, Z 0 ) ⊦ (f, 1, Z 0 ) uNote the last ID has no move. u is not accepted, because the input is not completely consumed.

44 Language of a PDA uThe common way to define the language of a PDA is by final state.  If P is a PDA, then L(P) is the set of strings w such that (q 0, w, Z 0 ) ⊦ * (f, ε,  ) for final state f and any .

45 Language of a PDA – (2) uAnother language defined by the same PDA is by empty stack.  If P is a PDA, then N(P) is the set of strings w such that (q 0, w, Z 0 ) ⊦ * (q, ε, ε ) for any state q.

46 Equivalence of Language Definitions 1.If L = L(P), then there is another PDA P’ such that L = N(P’). 2.If L = N(P), then there is another PDA P’’ such that L = L(P’’).

47 Proof: L(P) -> N(P’) Intuition uP’ will simulate P. uIf P accepts, P’ will empty its stack. uP’ has to avoid accidentally emptying its stack, so it uses a special bottom- marker to catch the case where P empties its stack without accepting.

48 Proof: N(P) -> L(P’’) Intuition uP” simulates P. uP” has a special bottom-marker to catch the situation where P empties its stack. uIf so, P” goes to an accepting state and accepts input.

49 Deterministic PDA’s uTo be deterministic, there must be at most one choice of move for any state q, input symbol a, and stack symbol X.  In addition, there must not be a choice between using input ε or real input.  Formally, δ (q, a, X) and δ (q, ε, X) cannot both be nonempty.