Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory VII.

Slides:



Advertisements
Similar presentations
Closure Properties of CFL's
Advertisements

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.
Context Free Grammars.
Lecture 17 Naveen Z Quazilbash Simplification of Grammars.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Western Michigan University CS6800 Advanced Theory of Computation Spring 2014 By Abduljaleel Alhasnawi & Rihab Almalki.
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.
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.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
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.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
104 Closure Properties of Regular Languages Regular languages are closed under many set operations. Let L 1 and L 2 be regular languages. (1) L 1  L 2.
Normal forms for Context-Free Grammars
1 Module 32 Chomsky Normal Form (CNF) –4 step process.
CS 3240 – Chapter 8.  Is a n b n c n context-free? CS Properties of Context-Free Languages2.
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.
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory II B Q.For  = {a, b} construct DFA that accepts all strings with exactly one.
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.
CS 3813 Introduction to Formal Languages and Automata Chapter 6 Simplification of Context-free Grammars and Normal Forms These class notes are based on.
Context-Free Grammars
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88.
CONVERTING TO CHOMSKY NORMAL FORM
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.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
Context Free Grammars CIS 361. Introduction Finite Automata accept all regular languages and only regular languages Many simple languages are non regular:
Languages & Grammars. Grammars  A set of rules which govern the structure of a language Fritz Fritz The dog The dog ate ate left left.
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory V Context-Free Grammars andLanguages.
Context-free Languages Chapter 2. Ambiguity.
Context Free Grammar. Introduction Why do we want to learn about Context Free Grammars?  Used in many parsers in compilers  Yet another compiler-compiler,
Introduction to Language Theory
Introduction to Theory of Automata By: Wasim Ahmad Khan.
Lecture 11 Theory of AUTOMATA
Chapter 6 Simplification of Context-free Grammars and Normal Forms These class notes are based on material from our textbook, An Introduction to Formal.
CSCI 3130: Formal languages and automata theory Tutorial 4 Chin.
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.
CSCI 2670 Introduction to Theory of Computing September 14, 2005.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
Dept. of Computer Science & IT, FUUAST Theory of Computation 2 Regular Expressions Regular Expression.
CS 154 Formal Languages and Computability March 8 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
1 1. Eliminate all  -transitions from the following FA without changing the number of states and the language accepted by the automaton. You should also.
Theory of Languages and Automata By: Mojtaba Khezrian.
Compiler Chapter 5. Context-free Grammar Dept. of Computer Engineering, Hansung University, Sung-Dong Kim.
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
David Rodriguez-Velazquez CS – 6800 Summer I
7. Properties of Context-Free Languages
CSC312 Automata Theory Grammatical Format Chapter # 13 by Cohen
Recap Lecture 34 Example of Ambiguous Grammar, Example of Unambiguous Grammer (PALINDROME), Total Language tree with examples (Finite and infinite trees),
Context-Free Grammars Pushdown Store Automata Properties of the CFLs
REGULAR LANGUAGES AND REGULAR GRAMMARS
NORMAL FORMS FDP ON THEORY OF COMPUTING
7. Properties of Context-Free Languages
Chapter 6 Simplification of Context-free Grammars and Normal Forms
Subject Name: Finite Automata & Formal Languages Subject Code 10CS56.
Context-Free Languages
Presentation transcript:

Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory VII

Dept. of Computer Science & IT, FUUAST Automata Theory 3 Automata Theory VII Simplification of CFG Elimination of 1)Useless Symbols or Productions: A variable A is useful if it is generating as : S  * xAy  * w. A  V and x,y in (V  T)* otherwise useless. If a variable is not reachable it is useless as B is useless in the following rules. B is not reachable from starting symbol S. S  A A  aA|  B  bA 2)  -productions (Empty Productions) A  , it is called “NULLABLE” 3)Unit Productions A  B

Dept. of Computer Science & IT, FUUAST Automata Theory 4 Automata Theory VII Examples: 1)Given a CFG as: G = ({S, A, B, C, E},{a,b,c}, P, S) P is defined as: S  AB A  a B  b B  C E  c |  New Grammar Ĝ is: Ĝ = ({S, A, B}, {a,b}, P’, S), P’ is given as: S  AB A  a B  b

Dept. of Computer Science & IT, FUUAST Automata Theory 5 Automata Theory VII Examples: 2)Given a CFG as: P is defined as: S  aS | A | C A  a B  aa C  aCb Production Rules P’ for the new grammar Ĝ are: S  aS | A A  a Draw a dependency graph to eliminate B. Useless symbols eliminated

Dept. of Computer Science & IT, FUUAST Automata Theory 6 Automata Theory VII Examples: 3) Given a CFG as: P is defined as: S  AB A  aAA |  B  bBB |  Production Rules P’ for the new grammar Ĝ are: S  AB | A | B A  aAA | aA | a B  bBB | bB | b  - Productions are eliminated

Dept. of Computer Science & IT, FUUAST Automata Theory 7 Automata Theory VII Examples: 4) Given a CFG as: G = ({S, A, B, C, D, E},{a,b}, P, S) P is defined as: S  AB A  a B  C | b C  D D  E E  a New Grammar Ĝ is: Ĝ = ({S, A, B, C, D}, {a,b}, P’, S), P’ is given as: S  AB A  a B  b B  a C  a D  a Eliminating unit production

Dept. of Computer Science & IT, FUUAST Automata Theory 8 Automata Theory VII Every nonempty CFL without  has a grammar G in which all productions are in one of two simpler forms, either: 1)A  BC, where A, B and C are each variables, or 2)A  a G has no useless symbols Chomsky Normal Form (CNF) “ Every context-free language can be generated by a grammar with no useless symbols and no unit productions”

Dept. of Computer Science & IT, FUUAST Automata Theory 9 Automata Theory VII Examples: 1) A grammar with production P is given S  aAbB A  aA | a B  bB | b For S  aAbB, we have S  B a AB b B B a  a B b  b For A  aA, we have A  B a A For B  bB, we have B  B b B New Grammar G 1 is given by G 1 = ({S, A, B, B a, B b }, {a,b},P’,S) P’ has productions S  B a AB b B A  B a A B  B b B B a  a B b  b A  a B  b Still not CNF change S  B a AB b B

Dept. of Computer Science & IT, FUUAST Automata Theory 10 Automata Theory VII Examples: CNF Grammar G1 is given by G 1 = ({S, A, B, B a, B b, D1, D2}, {a,b},P’,S) P’ has productions S  B a D 1 D 1  AD 2 D 2  B b B A  B a A B  B b B B a  a B b  b A  a B  b Now making S  B a AB b B into proper form we assume new variables D 1 and D 2 and the productions S  B a D 1 D 1  AD 2 D 2  B b B

Dept. of Computer Science & IT, FUUAST Automata Theory 11 Automata Theory VII Examples: 2) A grammar with production P is given S  ABa A  aab B  Ac For S  ABa, we have S  ABB a B a  a For A  aab we have A  B a B a B b B b  b For A  Ac, we have B  AB c B c  c For B  bB, we have B  B b B New Grammar G 1 is given by with P’ G 1 = ({S, A, B, B a, B b,B c }, {a,b,c},P’,S) P’ has productions S  ABB a A  B a B a B b B  AB c B a  a B b  b B c  c S  ABB a and A  B a B a B b are not in proper form

Dept. of Computer Science & IT, FUUAST Automata Theory 12 Automata Theory VII Examples: CNF Grammar G1 is given by G 1 = ({S, A, B, B a, B b, D1, D2}, {a,b,c},P’,S) P’ has productions S  A D 1 D 1  BB a A  B a D 2 D 2  B a B b B  AB c B a  a B b  b B c  c Now making S  ABB a and A  B a B a B b into proper form we assume new variables D 1 and D 2 and the productions S  A D 1 D 1  BB a A  B a D 2 D 2  B a B b

Dept. of Computer Science & IT, FUUAST Automata Theory 13 Automata Theory VII End of Chapter 7