Lecture 19 Naveen Z Quazilbash. Overview CNFs-Assignment Greibach Normal Forms.

Slides:



Advertisements
Similar presentations
Hector Miguel Chavez Western Michigan University.
Advertisements

Context free languages 1. Equivalence of context free grammars 2. Normal forms.
Closure Properties of CFL's
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.
1 Chomsky Normal Form of CFG’s Definition Purpose Method of Constuction.
Fall 2004COMP 3351 Simplifications of Context-Free Grammars.
Prof. Busch - LSU1 Simplifications of Context-Free Grammars.
Context Free Grammars.
Lecture # 11 Grammar Problems.
Lecture 17 Naveen Z Quazilbash Simplification of Grammars.
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory VII.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Western Michigan University CS6800 Advanced Theory of Computation Spring 2014 By Abduljaleel Alhasnawi & Rihab Almalki.
CS 3240 – Chapter 6.  6.1: Simplifying Grammars  Substitution  Removing useless variables  Removing λ  Removing unit productions  6.2: Normal Forms.
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.
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.
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
Costas Buch - RPI1 Simplifications of Context-Free Grammars.
1 Simplifications of Context-Free Grammars. 2 A Substitution Rule substitute B equivalent grammar.
Linear Grammars and Normal Forms (Lecture 21)
1 Simplifications of Context-Free Grammars. 2 A Substitution Rule Substitute Equivalent grammar.
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.
Specifying Languages CS 480/680 – Comparative Languages.
How to Convert a Context-Free Grammar to Greibach Normal Form
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.
Chapter 12: Context-Free Languages and Pushdown Automata
Context-Free Grammars
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.
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.
Context-Free Grammars – Chomsky Normal Form Lecture 16 Section 2.1 Wed, Sep 26, 2007.
1 Context-Free Languages Not all languages are regular. L 1 = {a n b n | n  0} is not regular. L 2 = {(), (()), ((())),...} is not regular.  some properties.
Chapter 5 Context-Free Grammars
Languages & Grammars. Grammars  A set of rules which govern the structure of a language Fritz Fritz The dog The dog ate ate left left.
Lecture 15 Naveen Z Quazilbash Ambiguity. Overview S-Grammars Ambiguity in Grammars Ambiguous grammars and Unambiguous Grammars.
Context Free Grammar. Introduction Why do we want to learn about Context Free Grammars?  Used in many parsers in compilers  Yet another compiler-compiler,
Transparency No. P2C2-1 Formal Language and Automata Theory PART II: Chapter 2 Linear Grammars and Normal Forms (Lecture 21)
Section 12.4 Context-Free Language Topics
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
CS 3240 – Chapter 5. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
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.
1 Efficient Parsing and Ambiguity. Ambiguity A grammar G is ambiguous if – There exists w ∊ L(G) such that – There are two parse trees for w Allows multiple.
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.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
Exercises on Chomsky Normal Form and CYK parsing
Chomsky Normal Form.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
Context-Free Grammars: an overview
Chomsky Normal Form CYK Algorithm
7. Properties of Context-Free Languages
CSC312 Automata Theory Grammatical Format Chapter # 13 by Cohen
Simplifications of Context-Free Grammars
Simplifications of Context-Free Grammars
Lecture 14 Grammars – Parse Trees– Normal Forms
Jaya Krishna, M.Tech, Assistant Professor
Chapter 7 Regular Grammars
NORMAL FORMS FDP ON THEORY OF COMPUTING
Context-Free Languages
Presentation transcript:

Lecture 19 Naveen Z Quazilbash

Overview CNFs-Assignment Greibach Normal Forms

Assignment Begin with the grammar: S  ASB| ε A  aAS|a B  SbS|A|bb 1. Are there any useless symbols? Eliminate them if so. 2. Eliminate ε-productions. 3. Eliminate unit productions. 4. Put the grammar into Chomsky normal form.

Greibach Normal Form Each production is of the form A  s or A  sB 1 B 2 B 3 …B n Where s is a symbol and B 1, B 2,…, B n are variables.

S-grammars (from lecture 15) Simple grammars a.k.a s-grammars. Rules for s-grammars: Productions of the form A  sB 1 B 2 B 3 ….B n,where s is a symbol and B 1 B 2 B 3 ….B n are variables. For each variable A and symbol s, there is at most one production of the form: A  sB 1 B 2 B 3 ….B n

S-grammars (2) (from lecture 15) For example, we can not have A  aBC A  aCD Because we must only have one “A  a…” production.

Difference Difference from s-grammars: for a given variable, we may have multiple productions with the same symbol. E.g. S  aS|a Two productions S  a… ==== OK for Greibach; not OK for s-grammars.

For every grammar that does not generate ε, there is an equivalent grammar in Greibach normal form. Example : S  aAbB A  aaA|a B  bB|b S  aAXB A  aYA|a B  bB|b X  b Y  a

Solution a)Only S is nullable, so we must choose, at each point where S occurs in a body, to eliminate it or not. Since there is no body that consists only of S's, we do not have to invoke the rule about not eliminating an entire body. The resulting grammar: S -> ASB | AB A -> aAS | aA | a B -> SbS | bS | Sb | b | A | bb b)The only unit production is B -> A. Thus, it suffices to replace this body A by the bodies of all the A-productions. The result: S -> ASB | AB A -> aAS | aA | a B -> SbS | bS | Sb | b | aAS | aA | a | bb

c)Observe that A and B each derive terminal strings, and therefore so does S. Thus, there are no useless symbols. d)Introduce variables and productions C -> a and D -> b, and use the new variables in all bodies that are not a single terminal: S -> ASB | AB A -> CAS | CA | a B -> SDS | DS | SD | b | CAS | CA | a | DD C -> a D -> b Finally, there are bodies of length 3; one, CAS, appears twice. Introduce new variables E, F, and G to split these bodies, yielding the CNF grammar: S -> AE | AB A -> CF | CA | a B -> SG | DS | SD | b | CF | CA | a | DD C -> a D -> b E -> SB F -> AS G -> DS