Context-Free Grammars – Chomsky Normal Form Lecture 16 Section 2.1 Wed, Sep 26, 2007.

Slides:



Advertisements
Similar presentations
Closure Properties of CFL's
Advertisements

CFGs and PDAs Sipser 2 (pages ). Long long ago…
101 The Cocke-Kasami-Younger Algorithm An example of bottom-up parsing, for CFG in Chomsky normal form G :S  AB | BB A  CC | AB | a B  BB | CA | b C.
Simplifying CFGs There are several ways in which context-free grammars can be simplified. One natural way is to eliminate useless symbols those that cannot.
About Grammars CS 130 Theory of Computation HMU Textbook: Sec 7.1, 6.3, 5.4.
Fall 2004COMP 3351 Simplifications of Context-Free Grammars.
Prof. Busch - LSU1 Simplifications of Context-Free Grammars.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
The CYK Algorithm David Rodriguez-Velazquez CS – 6800 Summer I
CS 3240 – Chapter 6.  6.1: Simplifying Grammars  Substitution  Removing useless variables  Removing λ  Removing unit productions  6.2: Normal Forms.
CFGs and PDAs Sipser 2 (pages ). Last time…
CS5371 Theory of Computation
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
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.
Costas Buch - RPI1 Simplifications of Context-Free Grammars.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
1 Converting NPDAs to Context-Free Grammars. 2 For any NPDA we will construct a context-free grammar with.
1 Simplifications of Context-Free Grammars. 2 A Substitution Rule substitute B equivalent grammar.
1 Regular Grammars Generate Regular Languages. 2 Theorem Regular grammars generate exactly the class of regular languages: If is a regular grammar then.
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
Normal forms for Context-Free Grammars
1 Module 32 Chomsky Normal Form (CNF) –4 step process.
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
1 Background Information for the Pumping Lemma for Context-Free Languages Definition: Let G = (V, T, P, S) be a CFL. If every production in P is of the.
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.
Homework #7 Solutions. #1. Use the pumping lemma for CFL’s to show L = {a i b j a i b j | i, j > 0} is not a CFL. Proof by contradiction using the Pumping.
1 The Pumping Lemma for Context-Free Languages. 2 Take an infinite context-free language Example: Generates an infinite number of different strings.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Chapter 12: Context-Free Languages and Pushdown Automata
Lecture 21: Languages and Grammars. Natural Language vs. Formal Language.
Formal Grammars Denning, Sections 3.3 to 3.6. Formal Grammar, Defined A formal grammar G is a four-tuple G = (N,T,P,  ), where N is a finite nonempty.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
CONVERTING TO CHOMSKY NORMAL FORM
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
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.
Normal Forms for Context-Free Grammars Definition: A symbol X in V  T is useless in a CFG G=(V, T, P, S) if there does not exist a derivation of the form.
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.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
Lecture 19 Naveen Z Quazilbash. Overview CNFs-Assignment Greibach Normal Forms.
Context-free Grammars [Section 2.1] - more powerful than regular languages - originally developed by linguists - important for compilation of programming.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Ambiguity.
Context-free Languages
Lecture # 9 Chap 4: Ambiguous Grammar. 2 Chomsky Hierarchy: Language Classification A grammar G is said to be – Regular if it is right linear where each.
Lecture 10UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 10.
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.
Closure Properties Lemma: Let A 1 and A 2 be two CF languages, then the union A 1  A 2 is context free as well. Proof: Assume that the two grammars are.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1 Chapter 6 Simplification of CFGs and Normal Forms.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Normal forms.
Lecture # 31 Theory Of Automata By Dr. MM Alam 1.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Exercises on Chomsky Normal Form and CYK parsing
Chomsky Normal Form.
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Theory of Languages and Automata By: Mojtaba Khezrian.
Computability Joke. Context-free grammars Parsing. Chomsky
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
Context-Free Grammars: an overview
Simplifications of Context-Free Grammars
Jaya Krishna, M.Tech, Assistant Professor
Regular Grammar.
CHAPTER 2 Context-Free Languages
Context-Free Languages
Presentation transcript:

Context-Free Grammars – Chomsky Normal Form Lecture 16 Section 2.1 Wed, Sep 26, 2007

Chomsky Normal Form A context-free grammar is in Chomsky Normal Form (CNF) if each rule is of the form A  BC, or A  a, where B and C are not S. Furthermore, the rule S   is allowed.

Chomsky Normal Form Theorem: Every context-free language is generated by a grammar in CNF.

Chomsky Normal Form Constructive proof (outline): Add a new start symbol S 0. Eliminate all  rules A  . Eliminate all unit rules A  B. Convert all remaining rules to the proper form.

Chomsky Normal Form Proof (detailed): Add a new start symbol S 0. Add the rule S 0  S. Eliminate all  rules A  . For each rule A   and each rule B  uAv, add a rule B  uv. Eliminate the rule A  .

Example Start with the grammar S  SXS |  X  ab |  Add the rule S 0  S

Example We now have S 0  S S  SXS |  X  ab | 

Example Apply the rules S   and X   to the other rules, creating the rules S  X S  SS S  XS S  SX S  S Don’t bother with the last rule.

Example Eliminate the rules S   X  

Example Add the rule S 0   because in the original, S could be replaced by .

Example We now have S 0  S |  S  SXS | SS | SX | XS | X X  ab

Chomsky Normal Form Proof (detailed): Eliminate all unit rules A  B. If A  B and B  u are rules, then add the rule A  u. Eliminate the rule A  B.

Chomsky Normal Form Add the rules S  ab S 0  SXS | SS | SX | XS | X | ab Eliminate the rules S 0  S S  X

Example We now have S 0  SXS | SS | SX | XS | ab |  S  SXS | SS | SX | XS | ab X  ab

Chomsky Normal Form Eliminate all mixed rules. Add rules A  a for all terminals appearing in strings of length  2. Then replace a with A in those strings.

Example Add the rules A  a B  b and rewrite the string ab as AB.

Example We now have S 0  SXS | SS | SX | XS | AB |  S  SXS | SS | SX | XS | AB X  AB A  a B  b

Chomsky Normal Form Finally, eliminate all long rules. Break all strings of length  2 into a series of strings of length 2.

Chomsky Normal Form Replace the rule A  B 1 B 2 …B k with A  B 1 C 1 C 1  B 2 C 2 … C k – 2  B k – 2 C k – 2 C k – 1  B k – 1 B k

Example Replace S 0  SXS S  SXS with S 0  SY S  SY Y  XS

Example The final result is S 0  SY | SS | SX | XS | AB |  S  SY | SS | SX | XS | AB X  AB Y  XS A  a B  b

A Derivation in CNF Use this grammar in CNF to derive the string ababab. S 0  SY  SXS  ABXS  ABABS  ABABAB  aBABAB  abABAB  abaBAB  ababAB  ababaB  ababab.

CNF Derivations Theorem: If a grammar G is in CNF and a string w in L(G) has length n, then w will be derived from G in exactly 2n – 1 steps.

The Membership Problem This theorem allows us to determine whether a given string is derivable from a given grammar. This is called the Membership Problem.

Example Show that the string abba is not derivable from the grammar of the previous example.

A Tree of all Possible Derivations S0S0 SYSSAB  abSYSSABSY SS ABXSABSS SY etc.

Example Put the grammar E  E + E | E * E | (E) | a | b | c into CNF. Then show that the string c++ is not derivable from it.