CSCI 2670 Introduction to Theory of Computing September 21, 2004.

Slides:



Advertisements
Similar presentations
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Advertisements

Erik Jonsson School of Engineering and Computer Science FEARLESS Engineering CS 4384 – 001 Automata Theory Thursday: Context-Free.
CFGs and PDAs Sipser 2 (pages ). Long long ago…
About Grammars CS 130 Theory of Computation HMU Textbook: Sec 7.1, 6.3, 5.4.
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory VII.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CSCI 2670 Introduction to Theory of Computing September 15, 2004.
Chapter 4 Normal Forms for CFGs Chomsky Normal Form n Defn A CFG G = (V, , P, S) is in chomsky normal form if each rule in G has one of.
CFGs and PDAs Sipser 2 (pages ). Last time…
CS5371 Theory of Computation
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 11, 2006.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.1: Context-Free Grammars) David Martin With some.
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
Context-Free Grammars Chapter 3. 2 Context-Free Grammars and Languages n Defn A context-free grammar is a quadruple (V, , P, S), where  V is.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Chapter 12: Context-Free Languages and Pushdown Automata
Problem of the DAY Create a regular context-free grammar that generates L= {w  {a,b}* : the number of a’s in w is not divisible by 3} Hint: start by designing.
1 Computer Language Theory Chapter 2: Context-Free Languages.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88.
CONVERTING TO CHOMSKY NORMAL FORM
Context-Free Grammars Normal Forms Chapter 11. Normal Forms A normal form F for a set C of data objects is a form, i.e., a set of syntactically valid.
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
The Pumping Lemma for Context Free Grammars. Chomsky Normal Form Chomsky Normal Form (CNF) is a simple and useful form of a CFG Every rule of a CNF grammar.
Context-Free Grammars – Chomsky Normal Form Lecture 16 Section 2.1 Wed, Sep 26, 2007.
Context-free Grammars [Section 2.1] - more powerful than regular languages - originally developed by linguists - important for compilation of programming.
Context Free Grammars CIS 361. Introduction Finite Automata accept all regular languages and only regular languages Many simple languages are non regular:
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Ambiguity.
CSCI 2670 Introduction to Theory of Computing September 15, 2005.
Context-free Languages
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory V Context-Free Grammars andLanguages.
CS 3240: Languages and Computation Context-Free Languages.
CSCI 2670 Introduction to Theory of Computing September 22, 2005.
Section 12.4 Context-Free Language Topics
Lecture 11 Theory of AUTOMATA
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
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.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
1 Chapter 6 Simplification of CFGs and Normal Forms.
CSCI 2670 Introduction to Theory of Computing September 23, 2004.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
CSCI 2670 Introduction to Theory of Computing September 14, 2005.
Structure and Ambiguity Removing Ambiguity Chomsky Normal Form Pushdown Automata Intro (who is he foolin', thinking that there will be time to get to this?)
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.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
Chomsky Normal Form.
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Theory of Languages and Automata By: Mojtaba Khezrian.
CSCI 2670 Introduction to Theory of Computing September 16, 2004.
Compiler Chapter 5. Context-free Grammar Dept. of Computer Engineering, Hansung University, Sung-Dong Kim.
Computability Joke. Context-free grammars Parsing. Chomsky
Context-Free Grammars: an overview
Complexity and Computability Theory I
CHAPTER 2 Context-Free Languages
فصل دوم Context-Free Languages
Chapter 2 Context-Free Language - 01
Presentation transcript:

CSCI 2670 Introduction to Theory of Computing September 21, 2004

Agenda Last week –Pumping lemma –Context-free grammars Examples, definition, strategies for building This week –More on CFG’s Ambiguity, Pushdown automata, pumping lemma for CFG’s Next week –Midterm (Chapters 1 & 2)

Announcement Homework due next Tuesday (9/28) –2.8, 2.9, 2.12, 2.13, 2.15, 2.18 d, 2.22

Ambiguity Consider the CFG ({S},{0,1},R,S), where the rules of R are S  0 | 1 | S + S | S * S Derive the string 0 * 1 + 1

Ambiguity S  0 | 1 | S + S | S * S 0 * S SS* S+S 0 11 S SS+ S*S 1 01 Different parse trees!

Leftmost derivation & ambiguity A derivation of a string w in a grammar G is a leftmost derivation if every step of the derivation replaced the leftmost variable A string is derived ambiguously in CFG G if it has two or more different leftmost derivations The grammar G is ambiguous if it generates some string ambiguously –Some grammars are inherently ambiguous

Chomsky normal form Method of simplifying a CFG Definition: A context-free grammar is in Chomsky normal form if every rule is of one of the following forms A  BC A  a where a is any terminal and A is any variable, and B, and C are any variables or terminals other than the start variable the rule S  ε is permitted, where S is the start variable

CFG’s and Chomsky normal form Theorem: Any context-free language is generated by a context-free grammar in Chomsky normal form. Proof idea: Convert any CFG to one in Chomsky normal form by removing or replacing all rules in the wrong form 1.Add a new start symbol 2.Eliminate ε rules of the form A  ε 3.Eliminate unit rules of the form A  B 4.Convert remaining rules into proper form

Convert a CFG to Chomsky normal form 1.Add a new start symbol -Create the following new rule S 0  S where S is the start symbol and S 0 is not used in the CFG

Convert a CFG to Chomsky normal form 2.Eliminate all ε rules A  ε, where A is not the start variable -For each rule with an occurrence of A on the right-hand side, add a new rule with the A deleted R  uAv becomes R  uAv | uv R  uAvAw becomes R  uAvAw | uvAw | uAvw | uvw -If we have R  A, replace it with R  ε unless we had already removed R  ε

Convert a CFG to Chomsky normal form 3.Eliminate all unit rules of the form A  B -For each rule B  u, add a new rule A  u, where u is a string of terminals and variables, unless this rule had already been removed -Repeat until all unit rules have been replaced

Convert a CFG to Chomsky normal form 4.Convert remaining rules into proper form -What’s left? -Replace each rule A  u 1 u 2 …u k, where k  3 and u i is a variable or a terminal with k-1 rules A  u 1 A 1 A 1  u 2 A 2 … A k-2  u k-1 u k

Example S  S 1 | S 2 S 1  S 1 b | Ab | ε A  aAb | ab S 2  S 2 a | Ba | ε B  bBa | ba Step 1: Add a new start symbol

Example S 0  S S  S 1 | S 2 S 1  S 1 b | Ab A  aAb | ab | ε S 2  S 2 a | Ba B  bBa | ba | ε Step 2: Eliminate ε rules

Example S 0  S S  S 1 | S 2 S 1  S 1 b | Ab | b A  aAb | ab S 2  S 2 a | Ba | a B  bBa | ba Step 3: Eliminate all unit rules

Example S 0  S 1 b | Ab | b | S 2 a | Ba | a S  S 1 b | Ab | b | S 2 a | Ba | a S 1  S 1 b | Ab | b A  aAb | ab S 2  S 2 a | Ba | a B  bBa | ba Step 4: Convert remaining rules to proper form

Example S 0  S 1 b | Ab | b | S 2 a | Ba | a S  S 1 b | Ab | b | S 2 a | Ba | a S 1  S 1 b | Ab | b A  aA 1 | ab A 1  Ab S 2  S 2 a | Ba | a B  bB 1 | ba B 1  Ba

Tomorrow Pushdown automata