Intro to Theory of Computation

Slides:



Advertisements
Similar presentations
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Advertisements

Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
CS5371 Theory of Computation
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
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.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
1 Computer Language Theory Chapter 2: Context-Free Languages.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Pushdown Automata.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
CSCI 2670 Introduction to Theory of Computing September 22, 2005.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
Lecture 14UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 14.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Theory of Computation Automata Theory Dr. Ayman Srour.
Theory of Languages and Automata By: Mojtaba Khezrian.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Recap: Nondeterministic Finite Automaton (NFA) A deterministic finite automaton (NFA) is a 5-tuple (Q, , ,s,F) where: Q is a finite set of elements called.
5. Context-Free Grammars and Languages
Formal Languages, Automata and Models of Computation
Pushdown Automata.
Formal Language & Automata Theory
CSE 105 theory of computation
CIS Automata and Formal Languages – Pei Wang
Pushdown Automata PDAs
Lecture 17 Oct 25, 2011 Section 2.1 (push-down automata)
Context Free Languages
Intro to Theory of Computation
Intro to Theory of Computation
Pushdown automata and CFG ↔ PDA conversions
Intro to Theory of Computation
Context-free Languages
5. Context-Free Grammars and Languages
Intro to Theory of Computation
CS21 Decidability and Tractability
Context-Free Grammars
Context-Free Languages
فصل دوم Context-Free Languages
Intro to Theory of Computation
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
Computer Language Theory
CSE 105 theory of computation
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Pushdown automata The Chinese University of Hong Kong Fall 2011
CSE 105 theory of computation
Sofya Raskhodnikova; Intro Theory of Computation
Intro to Theory of Computation
Intro to Theory of Computation
Intro to Theory of Computation
Intro to Theory of Computation
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

Intro to Theory of Computation LECTURE 7 Last time: Proving a language is not regular Pushdown automata (PDAs) Today: Context-free grammars (CFG) Equivalence of CFGs and PDAs CS 464 Sofya Raskhodnikova 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper CONTEXT-FREE GRAMMARS (CFGs) production rules start variable A → 0A1 A → B B → # variables terminals A  0A1  00A11  00B11  00#11 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper VALLEY GIRL GRAMMAR <PHRASE> → <FILLER><PHRASE> <PHRASE> → <START><END> <FILLER> → LIKE <FILLER> → UMM <START> → YOU KNOW <START> → ε <END> → GAG ME WITH A SPOON <END> → AS IF <END> → WHATEVER <END> → LOSER 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper VALLEY GIRL GRAMMAR <PHRASE> → <FILLER><PHRASE> | <START><END> <FILLER> → LIKE | UMM <START> → YOU KNOW | ε <END> → GAG ME WITH A SPOON | AS IF | WHATEVER | LOSER 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

A language is context-free if it is generated by some CFG. Formal Definition A CFG is a 4-tuple G = (V, Σ, R, S) V is a finite set of variables Σ is a finite set of terminals (disjoint from V) R is set of production rules of the form A → W, where A  V and W  (V∪Σ)* S  V is the start variable L(G) is the set of strings generated by G A language is context-free if it is generated by some CFG. 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Formal Definition A CFG is a 4-tuple G = (V, Σ, R, S) V is a finite set of variables Σ is a finite set of terminals (disjoint from V) R is set of production rules of the form A → W, where A  V and W  (V∪Σ)* S  V is the start variable Example: G = {{S}, {0,1}, R, S} R = { S → 0S1, S → ε } L(G) = { 0n1n | n ≥ 0 } 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper CFG terminology production rules start variable A → 0A1 A → B B → # variables terminals A  0A1  00A11  00B11  00#11 uVw yields uvw if (V → v)  R. A derives 00#11 in 4 steps. 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper Example GIVE A CFG FOR EVEN-LENGTH PALINDROMES S → S for all   Σ S → ε 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper Example GIVE A CFG FOR THE EMPTY SET G = { {S}, Σ, , S } 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper GIVE A CFG FOR… L3 = { strings of balanced parens } L4 = { aibjck | i, j, k ≥ 0 and (i = j or j = k) } 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper CFGs in the real world The syntactic grammar for the Java programming language BasicForStatement: for ( ; ; ) Statement for ( ; ; ForUpdate ) Statement for ( ; Expression ; ) Statement for ( ; Expression ; ForUpdate ) Statement for ( ForInit ; ; ) Statement for ( ForInit ; ; ForUpdate ) Statement for ( ForInit ; Expression ; ) Statement for ( ForInit ; Expression ; ForUpdate ) Statement 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper COMPILER MODULES LEXER PARSER SEMANTIC ANALYZER TRANSLATOR/INTERPRETER 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper Parse trees A A A B # 1 1 A  0A1  00A11  00B11  00#11 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper PDAs: reminder string pop push ε,ε → $ 0,ε → 0 1,0 → ε ε,$ → ε 1,0 → ε The language of P is the set of strings it accepts. PDAs are nondeterministic. 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

I-clicker problem (frequency: AC) When PDA takes a nondeterministic step, what happens to the stack? First 0 is pushed onto the stack, then 1. First 1 is pushed onto the stack, then 0. Now PDA has access to two stack and it pushes 0 onto one and 1 onto the other. Two different computational branches are available to the PDA: it pushes exactly one symbol (0 or 1) onto the stack on each branch. None of the above 1,ε → 0 q1 q0 1,ε → 1 q2 {madam, dad, but, tub, book}

Equivalence of CFGs & PDAs A language is generated by a CFG  It is recognized by a PDA 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Converting a CFG to a PDA Suppose L is generated by a CFG G = (V, Σ, R, S). Construct a PDA P = (Q, Σ, Γ, , q, F) that recognizes L. Idea: P will guess steps of a derivation of its input w and use its stack to derive it. 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper Algorithmic description of PDA (1) Place the marker symbol $ and the start variable on the stack. (2) Repeat forever: If a variable V is on top of the stack, and (V → s) ∈ R, pop V and push string s on the stack (b) If a terminal is on top of the stack, pop it and match it with input. Choose the rule from R nondeterministically. in reverse order. (3) On (ε,$), accept. 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

Sofya Raskhodnikova; based on slides by Nick Hopper Designing states of PDA (qstart) Push S$ and go to qloop (qloop) Repeat the following steps forever: (a) On (ε,V) where (V → s) ∈ R, push s and go to qloop (b) On (,), pop  and go to qloop (c) On (ε,$) go to qaccept Otherwise, the PDA will get stuck! 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

a,a → ε for each terminal a Designing PDA ε,ε → S$ ε,A → w for each rule A → w a,a → ε for each terminal a ε,$ → ε 11/10/2018 Sofya Raskhodnikova; based on slides by Nick Hopper

S → aTb T → Ta | ε ε,ε → $ ε,ε → T ε,S → b ε,ε → T ε,ε → S ε,T → a ε,$ → ε ε,ε → a ε,T → ε a,a → ε 11/10/2018 b,b → ε