CSE 105 theory of computation

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
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
1 Introduction to Computability Theory Lecture5: Context Free Languages Prof. Amos Israeli.
Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany.
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
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 4 Updated by Marek Perkowski.
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.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 Mälardalen University 2010.
Grammars CPSC 5135.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
11 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 7 School of Innovation, Design and Engineering Mälardalen University 2012.
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
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.
Lecture 6: Context-Free Languages
Theory of Languages and Automata By: Mojtaba Khezrian.
Theory of Languages and Automata By: Mojtaba Khezrian.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Language Recognition MSU CSE 260.
Closed book, closed notes
Context-Free Grammars: an overview
Formal Language & Automata Theory
G. Pullaiah College of Engineering and Technology
CSE 105 theory of computation
CSE 105 theory of computation
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
CSE 105 theory of computation
CS314 – Section 5 Recitation 3
PDAs Accept Context-Free Languages
PUSHDOWN AUTOMATA. PUSHDOWN AUTOMATA Hierarchy of languages Regular Languages  Finite State Machines, Regular Expression Context Free Languages 
Theory of Computation Lecture #27-28.
Chapter 7 PUSHDOWN AUTOMATA.
COSC 3340: Introduction to Theory of Computation
Pushdown automata and CFG ↔ PDA conversions
Context-free Languages
CSE 105 theory of computation
Intro to Data Structures
CHAPTER 2 Context-Free Languages
Context-Free Grammars
Context-Free Languages
CSE 105 theory of computation
فصل دوم Context-Free Languages
Pushdown automata a_introduction.htm.
Context-Free Languages
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
Theory of Computation Lecture #
… NPDAs continued.
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Pushdown automata The Chinese University of Hong Kong Fall 2011
Recap lecture 37 New format for FAs, input TAPE, START, ACCEPT , REJECT, READ states Examples of New Format of FAs, PUSHDOWN STACK , PUSH and POP states,
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

CSE 105 theory of computation Fall 2017 http://cseweb.ucsd.edu/classes/fa17/cse105-a/

Today's learning goals Sipser 2.1 Test if a specific string can be generated by a given context-free grammar Design a context-free grammar to generate a given language Determine if a context-free grammar is ambiguous Define push down automata Trace the computation of a push down automaton

Context-free languages over Σ Birds' eye view All languages over Σ Context-free languages over Σ Regular languages over Σ Finite languages over Σ

Can CFGs describe simple sets? Designing a CFG Can CFGs describe simple sets? Building a CFG to describe the language { abba } V = {S} Σ = ? R = { S  abba } S What's the set of terminals of this CFG? {a,b} V U S U Σ {S, a, b} {a,b, ε} I don't know.

Is every regular language a CFL? Approach 1: start with an arbitrary DFA M, build a CFG that generates L(M). Approach 2: build CFGs for {a}, {ε}, {}; then show that the class of CFL is closed under the regular operations (union, concatenation, Kleene star).

Approach 1 Claim: Given any DFA M, there is a CFG whose language is L(M). Construction: Trace computation using variables to denote state Given M = (Q,Σ,δ,q0,F) a DFA, define the CFG V = { Si | qi is in Q } Σ R = { Si  aSj | δ(qi,a) = qj } U { Si  ε | qi is in F} S = S0 Then prove correctness…

Approach 2 Build CFGs for {a}, {ε}, {}; then show that the class of CFL is closed under the regular operations (union, concatenation, Kleene star).

Approach 2 If G1 = (V1, Σ, R1, S1) and G2 = (V2, Σ, R2, S2) are CFGs and G1 describes L1, G2 describes L2, how can we combine the grammars so we describe L1 U L2 ? G = (V1 U V2, Σ, R1 U R2, S1 U S2) G = (V1 x V2, Σ, R1 x R2, (S1, S2) ) We might not always be able to: the class of CFG describable languages might not be closed under union. I don't know.

Approach 2 If G1 = (V1, Σ, R1, S1) and G2 = (V2, Σ, R2, S2) are CFGs and G1 describes L1, G2 describes L2, how can we combine the grammars so we describe L1 U L2 ?

We know this set is not regular! Designing a CFG We know this set is not regular! Building a CFG to describe the language { anbn | n ≥ 0 }

Designing a CFG Building a CFG to describe the language { anbn | n ≥ 0 } One approach: what is shortest string in the language? how do we go from shorter strings to longer ones?

Designing a CFG Building a CFG to describe the language { anbn | n ≥ 0 } V = { S } Σ = { a,b } R = S Which rules would complete this CFG? S  ε | ab S  ε | aS | Sb S  ε | aSb We need another variable other than S. I don't know.

Designing a CFG Also not a regular set Building a CFG to describe the language { 0n1m2n | n,m ≥ 0 } Hint: work from the outside in.

Designing a CFG Also not a regular set Building a CFG to describe the language { 0n1m2n | n,m ≥ 0 } Hint: work from the outside in. V = { S, T } Σ = { 0,1,2 } R = { S  0S2 | T | ε , T  1T | ε } S

CFGs in the wild V = {E}, Σ = {1,+,x,(,)}, R = { E  E+E | ExE | (E) | 1 }, S=E Describing well-formed arithmetic expressions Which of the followings strings is generated by this CFG? E 11 1+1x1 ε I don't know.

Derivations and parsing E  E+E | ExE | (E) | 1 Lots of derivations for 1+1x1

Derivations and parsing E  E+E | ExE | (E) | 1 Lots of derivations for 1+1x1

Derivations and parsing E  E+E | ExE | (E) | 1 Lots of derivations for 1+1x1 A string is ambiguously derived in a CFG if it has more than one leftmost derivation i.e. more than one parsing tree

Recap: Context-free languages Context-free grammar One-step derivation Derivation Language generated by grammar

An alternative … Sipser p. 109 NFA + stack

Pushdown automata Sipser p. 109 NFA + stack At each step 1. Transition to new state based on current state, letter read, and top letter of stack. 2. (Possibly) push or pop a letter to (or from) top of stack

Pushdown automata Sipser p. 109 NFA + stack Accept a string if there is some sequence of states and some sequence of stack contents which processes the entire input string and ends in an accepting state.

State diagram for PDA Sipser p. 109 If hand-drawn or in Sipser State transition labelled a, b  c means "when machine reads an a from the input and the top symbol of the stack is a b, it may replace the b with a c."

State diagram for PDA Sipser p. 109 If hand-drawn or in Sipser State transition labelled a, b  c means "when machine reads an a from the input and the top symbol of the stack is a b, it may replace the b with a c." What edge label would indicate "Read a 0, don't pop anything from stack, don’t push anything to the stack"? 0, ε  ε ε, 0  ε ε, ε  0 ε  ε, 0 I don't know.

Formal definition of PDA Sipser Def 2.13 p. 111