CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.

Slides:



Advertisements
Similar presentations
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Advertisements

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.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
1 Converting NPDAs to Context-Free Grammars. 2 For any NPDA we will construct a context-free grammar with.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
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.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Chapter 7 PDA and CFLs.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
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.
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.
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.
1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages.
Formal Languages, Automata and Models of Computation
CS 154 Formal Languages and Computability February 4 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CS 154 Formal Languages and Computability February 9 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
CS 154 Formal Languages and Computability March 8 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
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,
CS 154 Formal Languages and Computability March 17 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability March 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Theory of Languages and Automata By: Mojtaba Khezrian.
CS 154 Formal Languages and Computability March 22 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Formal Languages, Automata and Models of Computation
Theory of Computation Pushdown Automata pda Lecture #10.
PDAs Accept Context-Free Languages
NPDAs Accept Context-Free Languages
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
Pushdown Automata PDAs
Chapter 7 PUSHDOWN AUTOMATA.
NPDAs Accept Context-Free Languages
فصل دوم Context-Free Languages
… NPDAs continued.
Pushdown automata The Chinese University of Hong Kong Fall 2011
Normal Forms for Context-free Grammars
Presentation transcript:

CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Context-Free Languages and NPDAs  For any context-free language L, there exists an NPDA M such that L = L(M).  If L = L(M) for some NPDA M, then L is a context-free language. 2

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Convert a DFA to a Regular Grammar  Construct a right-linear regular grammar such that the derivation of a string mimics how the DFA processes that string. Each production is either or.  Introduce a variable for each state.  For each transition add the production  If B is a final state, add the production 3

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Example: DFA  Regular Grammar  Add variables S, A, B, and C. 4 For the regular expression ( )*11

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Convert a Context-Free Grammar to a PDA  The PDA picks a leftmost derivation and checks whether or not it was correct.  Do this using only a stack for storage. 5

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Convert a CFG to a PDA, cont’d  Match terminals to the left of the leftmost variable to symbols in the input string.  Push the remaining symbols of the production onto the stack, with the leftmost symbol on top.  At each step: Variable on top of the stack: Pick a production and replace the variable by the right-hand side. Terminal on top: Pop the symbol and check that it matches the current input symbol (reject if not).  When the stack is empty, check that the input is done (reject if not). 6

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Example: CFG  PDA  From the context-free grammar do a leftmost derivation of the string : 7 S 0S1S 01S 011S0S 0111S0S0S 01110S0S S

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Example: CFG  PDA, cont’d 8 InputStack (top at left) ActionProduction S replace S  0S1S S1S0S1S pop and match 11100S1SS1S replace S  λS  λ S1S pop and match 1100S replace S  1S0S 11001S0S1S0S pop and match 100S0SS0S replace S  1S0S 1001S0S0S1S0S0S pop and match 00S0S0SS0S0S replace S  λS  λ 000S0S0S0S pop and match 0S0SS0S replace S  λS  λ 00S0S pop and match S replace S  λS  λ accept

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Example: CFG  PDA, cont’d  Convert the grammar to Greibach normal form:  The PDA will have three states {q 0, q 1, q 2 } with initial state q 0 and final state q 2. 9

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Example: CFG  PDA, cont’d  Stack start symbol: z 10

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Convert an NPDA to a Context-Free Grammar  Basically, reverse the previous process so that the grammar simulates the moves of the PDA.  The variable part of a sentential form should be the content of the stack.  The terminal prefix of a sentential form should be the processed input symbols. 11

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Convert an NPDA to a CFG, cont’d  We can label the variables of the grammar (qAp) such that if and only if the NPDA removes A from the stack while reading v and going from state q to state p.  Therefore, if we choose (q 0 zq f ) as the start symbol, then if and only if the NPDA removes the stack start symbol z (thus creating an empty stack) while reading w and going from state q 0 to state q f. But that’s how the NPDA accepts w. 12

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Convert an NPDA to a CFG, cont’d  Pop: In state q, pop symbol A while reading a and going to state p. Add the production  Push: In state q with A on top of the stack, push B while reading a and going to state p. Add the collection of productions for every state r and s. To erase A, first push B, then erase B going from state p to s, and finally erase A going from state s to r. 13

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Example: NPDA  CFG  Let 14 Start Read Push 1 PopReadPop Accept a 1 λ 0 b

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Example: NPDA  CFG, cont’d  Start symbol: (q 0 0q 2 )  Three pops: 15

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Example: NPDA  CFG, cont’d  Pushes: 18 productions of the form for each and  Do not include useless productions such as 16

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Example: NPDA  CFG, cont’d  The final CFG with start symbol (q 0 0q 2 ): 17 Demo: G8.5x

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Deterministic Context-Free Language  A deterministic pushdown automaton (DPDA) never has a choice in its move.  The set δ(q, a, b) contains only one element. Given an input symbol and a symbol at the top of the stack, at most one move is possible.  If δ(q, λ, b) is not empty, then δ(q, c, b) must be empty for every c in Σ. If an λ -move is possible for some configuration, no input-consuming alternative is available. 18

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Example Deterministic CFL  The language is deterministic context-free language.  The transition function of its PDA with the stack start symbol 0 is 19

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak NPDA for 20 Start Rea d Push a Push b ab Pop Accept Rea d Pop a b ab z λ Q = {q 0, q 1, q 2 } Σ = {a, b}  = {a, b, z} stack start symbol = z F = {q 2 }  Push w onto the stack:  Guess the string middle:  Match input w R vs. stack:  Successful match: δ(q 0, a, a) = { (q 0, aa) } δ(q 0, b, a) = { (q 0, ba) } δ(q 0, a, b) = { (q 0, ab) } δ(q 0, b, b) = { (q 0, bb) } δ(q 0, a, z) = { (q 0, az) } δ(q 0, b, z) = { (q 0, bz) } δ(q 0,, a) = { (q 1, a) } δ(q 0,, b) = { (q 1, b) } δ(q 1, a, a) = { (q 1, ) } δ(q 1, b, b) = { (q 1, ) } δ(q 1,, z) = { (q 2, z) } q0q0 q2q2 q1q1 Guess!

Computer Science Dept. Spring 2016: March 15 CS 154: Formal Languages and Computability © R. Mak Pumping Lemma for Context-Free Languages  Yes, there is one for context-free languages, too.  Like the one for regular languages, use the pumping lemma to prove that a language is not context-free.  Unfortunately, it’s even harder to use than the one for regular languages. 21