CS 3240 – Chapter 7. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.

Slides:



Advertisements
Similar presentations
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Advertisements

Chapter 5 Pushdown Automata
1 Pushdown Automata (PDA) Informally: –A PDA is an NFA-ε with a stack. –Transitions are modified to accommodate stack operations. Questions: –What is a.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Pushdown Automata CPSC 388 Ellen Walker Hiram College.
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.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
CS 3240 – Chapter 3.  How would you delete all C++ files from a directory from the command line?  How about all PowerPoint files that start with the.
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.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
CS 490: Automata and Language Theory Daniel Firpo Spring 2003.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
CS Chapter 2. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
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.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
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.
Pushdown Automata.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
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.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein.
CS 3240 – Chapter 5. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
Chapter 7 Pushdown Automata
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03A - Pushdown automata Programming Language Design.
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.
Formal Languages, Automata and Models of Computation
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,
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 3240 – Chapter 9.  Turing Machines  From Alan Turing, 1936  Turns out to be the LAST machine  The only machine you'll ever need  The Church-Turing.
CS6800 Advance Theory of Computation Spring 2016 Nasser Alsaedi
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.
PDAs Accept Context-Free Languages
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata.
PUSHDOWN AUTOMATA. PUSHDOWN AUTOMATA Hierarchy of languages Regular Languages  Finite State Machines, Regular Expression Context Free Languages 
Chapter 7 PUSHDOWN AUTOMATA.
NPDAs Accept Context-Free Languages
Intro to Data Structures
… NPDAs continued.
Pushdown automata The Chinese University of Hong Kong Fall 2011
Presentation transcript:

CS 3240 – Chapter 7

LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar Recursively Enumerable Turing MachineUnrestricted Phrase- Structure Grammar 2CS Introduction

 Take an FA and add a stack  A restricted form of unbounded memory  Operations:  Pop  Push  Ignore (λ)  (Pop always precedes push) 3CS Pushdown Automata

 Three items per transition edge ,,  any or all could be λ  A PDA accepts when:  An accepting state is reached, and  The stack is empty ▪ Different from book! ▪ The machine crashes when no move is possible ▪ implicit jail 4CS Pushdown Automata

A deterministic PDA (no choices; λ is okay sometimes). The stack alphabet (Γ = {X}) can differ from the input alphabet (Σ = {a, b}). Trace aabb… 5CS Pushdown Automata

q 0 aabbλ q 0 abbX q 0 bbXX q 1 bX q 1 λλ 6CS Pushdown Automata Traditional notation (see book): (q 0,aabb, λ) ⊢ (q 0,abb,X) ⊢ (q 0,bb,XX) ⊢ (q 1,b,X) ⊢ (q 1,λ, λ) Also: (q 0,aabb,λ) ⊢ * (q 1,λ, λ) ( ⇒ aabb ∈ L)

7CS Pushdown Automata

8 How would you do a 2n b n ?

CS Pushdown Automata9 Each b must pop 2 X’s

Is this deterministic? Trace the string abaacaaba. 10CS Pushdown Automata

 Input: (state-1, input character, pop character)  Output: (state-2, push character(s))  Example: The edge (a,λ,a) on previous slide: δ(q 0,a,λ) = (q 0,a)  Exercise:  Rewrite wcw R in functional form CS Pushdown Automata11

Is this deterministic? Trace the string abaaaaaba. Trace the string abaabaaba. Trace the string abaaaaba. 12CS Pushdown Automata

13 Trace aaabbbb The grammar: S → aSb | aSbb | λ

CS Pushdown Automata14 Trace ababbaab

CS Pushdown Automata15

CS Pushdown Automata16 Try abababbbb. How would you do Twice a ? Reasoning: There must be 2 b’s for every a. When we read an a, there are three possibilities: 1)Its 2 b’s have already been read 2)1 b has been read and 1 remains 3)Both b’s are yet to be read

CS Pushdown Automata17

CS Pushdown Automata18

CS Pushdown Automata19

 Q:set of states  ∑: input alphabet  Γ: stack alphabet  δ: Q x (∑ ∪ λ) x (Γ ∪ λ) → finite subsets of Q x Γ *  q 0 : start state  F ⊆ Q: final states  (z Γ: optional stack start symbol) CS Pushdown Automata20

 Not strictly necessary  Can serve as a “bottom marker” to allow detection of an empty stack  A convenience  Can make things easier to design/understand  Sometimes handy when seeking an associated CFG  Can eliminate some lambda pops ▪ Handy later CS Pushdown Automata21

CS Pushdown Automata22

CS Pushdown Automata23

CS Pushdown Automata24

CS Pushdown Automata25

 How do we know that PDAs are the correct machine model for CFLs?  1) Must show that for any CFG, there is a PDA that accepts its language  2) Must show that for any PDA, there is a CFG that generates its language  The first case is easier than the second!  It can be handy to go back and forth CS Pushdown Automata26

 The leading character is read  The LHS variable is popped  The RHS string is pushed  Initial transition pushes S  See next slide CS Pushdown Automata27

CS Pushdown Automata28

CS Pushdown Automata29

 Very trivial (Yay!)  But the (2-state) PDA is non-deterministic  State-2 is a final state  1) Push S on the stack; move to state-2  2) For every rule, have a transition that:  pops the left-hand side and pushes the right-hand side  3) For every character, c, in Σ, have a rule that:  consumes and pops c simultaneously CS Pushdown Automata30

CS Pushdown Automata31 S → aSb | aSbb | λ Trace aaabbbbb: (q 0,aaabbbbb,λ) ⊢ (q 1,aaabbbbb,S) ⊢ (q 1,aaabbbbb,aSbb) ⊢ (q 1,aabbbbb,Sbb) ⊢ (q 1,aabbbbb,aSbbbb) ⊢ (q 1,abbbbb,Sbbbb) ⊢ (q 1,abbbbb,aSbbbbb) ⊢ (q 1,bbbbb,Sbbbbb) ⊢ (q 1,bbbbb,bbbbb) ⊢ * (q 1,λ,λ)

CS Pushdown Automata32 S → aSbSbS | bSaSbS | bSbSaS | λ … And trace bbabaabbb

CS Pushdown Automata33 S => (S) | SS | λ Derive ()(()) from the grammar. Then accept it by the machine. Then find a one-state DPDA for this language.

 We need to relate PDA movement to a CFG production rule somehow  Key: consuming a character in the PDA corresponds to generating a character in the CFG  The stack contents must also be part of all this CS Pushdown Automata34

 PDAs of the form below have a natural translation to a CFG  the reverse of CFG-to-PDA conversion  (conveniently) call the stack start symbol S  Translate each transition in state-2 into a rule: ▪ c,X,Y X → cY (i.e., → ) ▪ (X cannot be λ) CS Pushdown Automata35

CS Pushdown Automata36 S → aXS | bYS | λ X → aXX | bYX | b Y → bYY | aXY | a Derive abbbaaba

CS Pushdown Automata37 Go back and find grammars for slides 22, Also, work backward from the (()) DPDA to a grammar.

 We must also track state changes  Our variables must therefore contain state and stack information  Very tricky! CS Pushdown Automata38

 Suppose X is on the stack and ‘a’ is read  What can happen to X?  It will be popped (and possibly put back)  It may be replaced by one or more other stack symbols ▪ Which symbols will also later be popped, replaced, etc… ▪ The stack grows and shrinks and grows and shrinks …  Eventually, as more input is consumed, the effect of having pushed X on the stack must be erased (or we’ll never reach an empty stack!)  And the state may change many times! CS Pushdown Automata39

… (q i, x 1 x 2 …x k, Y 1 Y 2 …Y k ) ⊢ * (q j, x 2 …x k, Y 2 …Y k ) ⊢ * (q n, x k, Y k ) ⊢ * (q f, λ, λ) 40CS Pushdown Automata

 Let the symbol represent the sequence of movements in a PDA that:  starts in state q  eventually ends in state p  eventually removes A and its after-effects from the stack  The symbol then represents accepting a valid string (if s is the start state and f is a final state)  These symbols will be our variables  Because they track the machine configuration that accepts strings  Just as the grammar will generate those strings 41CS Pushdown Automata

 Consider the transition δ(q,a,X) = (p,Y)  This means that a is consumed, X is popped, we move directly to state p, and subsequent processing must eventually erase Y and its follow-on effects  A corresponding grammar rule is:  → a (?’s represent the same state)  We don’t know where we’ll eventually end up when the stack is back to where it was before the X was first pushed  All we know is we immediately go through p  So we entertain all possibilities (see 3 and 4 on next slide) 42CS Pushdown Automata

 1) S → for all final states, f  2) → λ for all states, q  These will serve as terminators  3) For transitions δ(q,a,X) = (p,Y):  → a for all states, r  4) For transitions δ(q,a,X) = (p,Y 1 Y 2 ):  → a for all states, r, s  And so on, for longer pushed strings 43CS Pushdown Automata

 The process requires:  No multiple pops ▪ So spread them out over multiple states if needed  Also, for every lambda-pop c,λ,X:  Add an equivalent rule for each letter of Γ (the stack alphabet) as follows: ▪ (c,X,XX) ▪ (c,Y,XY) ▪ etc. ▪ And keep the original lambda pop!!! CS Pushdown Automata44

45CS Pushdown Automata Call the start state, s, and the final state, f. Add the following transition on s: (a,X,XX) 1) S → 2) → λ; → λ Now go through each transition…

1. δ(s,a,λ) = (s,X):  → a 2. δ(s,a,X) = (s,XX):  → a CS Pushdown Automata46

3. δ(s,b,X) = (f,λ):  → b 4. δ(f,b,X) = (f,λ):  → b CS Pushdown Automata47

CS Pushdown Automata48 S → → a | λ → λ → a → a | a | b → b

CS Pushdown Automata49 S → → a | λ → a → a | a | b → b

CS Pushdown Automata50 S → → a → a | b → b

CS Pushdown Automata51 S → a → a | b → b

CS Pushdown Automata52 S → a → a b | b

CS Pushdown Automata53 S → aX X → aXb | b Done! (finally :-)

 Find a CFG for n b = n a + 1 using the generic conversion process CS Pushdown Automata54

 A PDA is deterministic if there are no choices:  Depends on a state’s pair:  1) δ(q,a,X) has only one choice (a could be λ), and  2) If a is not λ, then there is no δ(q,λ,X) edge, and  3) if X is not λ, then there is no δ(q,a,λ) edge.  NOTE: Some PDAs are inherently non- deterministic (no deterministic equivalent, e.g., ww R ) CS Pushdown Automata55

 Revisit previous PDAs and check for determinacy CS Pushdown Automata56

Languages accepted by nondeterministic PDA Languages accepted by deterministic PDA Languages accepted by DFA CS Pushdown Automata57