Context Free Grammar: Simplification

Slides:



Advertisements
Similar presentations
4.5 Inherently Ambiguous Context-free Language For some context-free languages, such as arithmetic expressions, may have many different CFG’s to generate.
Advertisements

Erik Jonsson School of Engineering and Computer Science FEARLESS Engineering CS 4384 – 001 Automata Theory Thursday: Context-Free.
Lecture # 8 Chapter # 4: Syntax Analysis. Practice Context Free Grammars a) CFG generating alternating sequence of 0’s and 1’s b) CFG in which no consecutive.
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.
SIMPLIFYING GRAMMARS Definition: A useless symbol of a context-free
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
Conversion of a Chomsky normal form grammar to Greibach normal form
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.
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
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
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
1 CSCI 3130: Formal Languages and Automata Theory Tutorial 4 Hung Chun Ho Office: SHB 1026 Department of Computer Science & Engineering.
Normal forms for Context-Free Grammars
1 Module 32 Chomsky Normal Form (CNF) –4 step process.
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.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Context-Free Grammars
نظریه زبان ها و ماشین ها فصل دوم 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.
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:
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.
Context Free Grammar. Introduction Why do we want to learn about Context Free Grammars?  Used in many parsers in compilers  Yet another compiler-compiler,
CS 3240: Languages and Computation Context-Free Languages.
Grammar G = (V N, V T, P, S) –V N : Nonterminal symbols –V T : Terminal symbols V N  V T = , V N ∪ V T = V – P : a finite set of production rules α 
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.
1 Chapter 6 Simplification of CFGs and Normal Forms.
Syntax Analyzer (Parser)
Context Free Grammars and Regular Grammars Needs for CFG Grammars and Production Rules Context Free Grammars (CFG) Regular Grammars (RG)
Lecture # 10 Grammar Problems. Problems with grammar Ambiguity Left Recursion Left Factoring Removal of Useless Symbols These can create problems for.
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Context Free Grammars & Parsing CPSC 388 Fall 2001 Ellen Walker Hiram College.
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
Context-Free Grammars: an overview
Formal Language & Automata Theory
LR(k) grammars The Chinese University of Hong Kong Fall 2009
Syntax Specification and Analysis
Complexity and Computability Theory I
7. Properties of Context-Free Languages
Simplifications of Context-Free Grammars
Compiler Construction
FORMAL LANGUAGES AND AUTOMATA THEORY
Lecture 14 Grammars – Parse Trees– Normal Forms
Jaya Krishna, M.Tech, Assistant Professor
Context-Free Languages
Context Free Grammar: Parse Tree
LR(1) grammars The Chinese University of Hong Kong Fall 2010
NORMAL FORMS FDP ON THEORY OF COMPUTING
7. Properties of Context-Free Languages
Subject Name: Finite Automata & Formal Languages Subject Code 10CS56.
Chapter 2 Context-Free Language - 01
Theory of Computation Lecture #
LR(1) grammars The Chinese University of Hong Kong Fall 2011
LR(k) grammars The Chinese University of Hong Kong Fall 2008
Context-Free Grammars
Context-Free Languages
Presentation transcript:

Context Free Grammar: Simplification Erwin Yudi Hidayat erwin@dsn.dinus.ac.id

CFG Simplification Purpose: to limit or minimize complexity in parsing a tree due to unnecessary production rule Example: production rule in CFG is defined as follow: SAB  a Aa ???

CFG Simplification Purpose: to limit or minimize complexity in parsing a tree due to unnecessary production rule Example: production rule in CFG is defined as follow: SAB  a Aa B has no derivation...

D  A : causes complexity (redundant) CFG Simplification What about this one? SA AB BC CD Da  A Lengthy path D  A : causes complexity (redundant)

CFG Simplification Context Free Grammar can be simplified by: Useless production elimination Unit production elimination  production elimination

Useless Production Elimination Useless production is defined as: Any production contains variable which has no derivation to produce terminals. This production is useless as endless derivation (variable symbol still remains) Any production that never can be reached using any derivation from start symbol, therefore this production is redundant.

Useless Production Elimination Example: production rule in CFG is as follow: SaSa Abd  Bde AAda BBBB  a Variable A has no derivation to reach terminal As consequence, S Abd has no derivation Simplified CFG: SaSa  Bde

Useless Production Elimination Example: production rule in CFG is as follow: S Aa  B Aab  D Bb  E Cbb EaEa Variable E has no derivation to reach terminal Variable D has no derivation to reach terminal Variable C never be used Simplified CFG: SAa  B Aab Bb

Unit Production Elimination Unit production is defined as any production that consist only one single variable symbol, e.g. A B, C  D Example: production rule in CFG is as follow: SSb SC CD Cef Ddd

Unit Production Elimination Unit production is defined as any production that consist only one single variable symbol, e.g. A B, C  D Example: production rule in CFG is as follow: SSb SC CD Cef Ddd

Unit Production Elimination Unit production is defined as any production that consist only one single variable symbol, e.g. A B, C  D Example: production rule in CFG is as follow: SSb SC Cdd Cef Ddd

Unit Production Elimination Unit production is defined as any production that consist only one single variable symbol, e.g. A B, C  D Example: production rule in CFG is as follow: SSb SC Cdd Cef Ddd

Unit Production Elimination Unit production is defined as any production that consist only one single variable symbol, e.g. A B, C  D Example: production rule in CFG is as follow: SSb Sdd | ef Cdd Cef Ddd

Unit Production Elimination Unit production is defined as any production that consist only one single variable symbol, e.g. A B, C  D Example: production rule after simplification: SSb Sdd | ef Cdd Cef Ddd

Unit Production Elimination Ctd...