Cs466(Prasad)L8Norm1 Normal Forms Chomsky Normal Form Griebach Normal Form.

Slides:



Advertisements
Similar presentations
Context free languages 1. Equivalence of context free grammars 2. Normal forms.
Advertisements

Closure Properties of CFL's
1 Parsing The scanner recognizes words The parser recognizes syntactic units Parser operations: Check and verify syntax based on specified syntax rules.
Exercise 1: Balanced Parentheses Show that the following balanced parentheses grammar is ambiguous (by finding two parse trees for some input sequence)
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.
Context Free Grammars.
Lecture # 11 Grammar Problems.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
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
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 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Parsing III (Eliminating left recursion, recursive descent parsing)
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.
1 Simplifications of Context-Free Grammars. 2 A Substitution Rule substitute B equivalent grammar.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
1 Simplifications of Context-Free Grammars. 2 A Substitution Rule Substitute Equivalent grammar.
CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)
Normal forms for Context-Free Grammars
1 Module 32 Chomsky Normal Form (CNF) –4 step process.
Parsing SLP Chapter 13. 7/2/2015 Speech and Language Processing - Jurafsky and Martin 2 Outline  Parsing with CFGs  Bottom-up, top-down  CKY parsing.
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
1 Applications of Regular Closure. 2 The intersection of a context-free language and a regular language is a context-free language context free regular.
CS 3813 Introduction to Formal Languages and Automata Chapter 6 Simplification of Context-free Grammars and Normal Forms These class notes are based on.
Chapter 4 Context-Free Languages Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
CONVERTING TO CHOMSKY NORMAL FORM
Formal Languages Context free languages provide a convenient notation for recursive description of languages. The original goal of CFL was to formalize.
Pushdown Automata (PDA) Intro
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.
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:
CYK Algorithm for Parsing General Context-Free Grammars
Chapter 6 Simplification of Context-free Grammars and Normal Forms These class notes are based on material from our textbook, An Introduction to Formal.
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.
Recursive Data Structures and Grammars Themes –Recursive Description of Data Structures –Grammars and Parsing –Recursive Definitions of Properties of Data.
Top-down Parsing. 2 Parsing Techniques Top-down parsers (LL(1), recursive descent) Start at the root of the parse tree and grow toward leaves Pick a production.
1 Chapter 6 Simplification of CFGs and Normal Forms.
CYK Algorithm for Parsing General Context-Free Grammars.
Grammars A grammar is a 4-tuple G = (V, T, P, S) where 1)V is a set of nonterminal symbols (also called variables or syntactic categories) 2)T is a finite.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
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.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
Exercises on Chomsky Normal Form and CYK parsing
Chomsky Normal Form.
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.
Theory of Computation Automata Theory Dr. Ayman Srour.
Compiler Chapter 5. Context-free Grammar Dept. of Computer Engineering, Hansung University, Sung-Dong Kim.
Closed book, closed notes
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
Context-Free Grammars: an overview
Complexity and Computability Theory I
CSC312 Automata Theory Grammatical Format Chapter # 13 by Cohen
Lecture 22 Pumping Lemma for Context Free Languages
Simplifications of Context-Free Grammars
Simplifications of Context-Free Grammars
Chapter 6 Simplification of Context-free Grammars and Normal Forms
CHAPTER 2 Context-Free Languages
Applications of Regular Closure
Normal Forms for Context-free Grammars
Context-Free Languages
Presentation transcript:

cs466(Prasad)L8Norm1 Normal Forms Chomsky Normal Form Griebach Normal Form

cs466(Prasad)L8Norm2 Language preserving transformations Improve parsing efficiency Prove properties about languages and derivations Shorter derivations

cs466(Prasad)L8Norm3 Elimination of  rules Reduces the length of the derivation

cs466(Prasad)L8Norm4 Aim: Restrict the grammar such that Approach: –Introduce S’

cs466(Prasad)L8Norm5 –Add rules to capture the effect of -rules to be deleted. – (Ensures non-contracting rules)

cs466(Prasad)L8Norm6 Example

cs466(Prasad)L8Norm7 Determination of nullable non-terminals Bottom-up flow of information

cs466(Prasad)L8Norm8 Algorithm Nullable Nonterminals NULL := {A | A ->  P}; repeat PREV := NULL ; foreach A  V do if there is an A-rule A -> w and w  PREV* then NULL := NULL U {A} until NULL = PREV;

cs466(Prasad)L8Norm9 Proof of correctness Soundness –If A  NULL (final) then A=>*. Induction on the number of iterations of the loop. Completeness –If A=>* then A  NULL (final). Induction on the minimal derivation of the null string from a non-terminal. Termination Bounded by the number of non-terminals.

cs466(Prasad)L8Norm10 Elimination of Chain  rules Removing renaming rules: redundant procedure calls. Top-down flow of information

cs466(Prasad)L8Norm11 Construction of Chain (A) Chain (A) := {A}; PREV :=  ; repeat NEW := Chain (A) - PREV; PREV := Chain (A); foreach B  NEW do if there is a rule B -> C then Chain (A) := Chain (A) U {C} until Chain (A) = PREV;

cs466(Prasad)L8Norm12 Examples

cs466(Prasad)L8Norm13 Elimination of useless symbols usefulA variable is useful if it occurs in a derivation that begins with the start symbol and generates a terminal string. Reachable from S Derives terminal string

cs466(Prasad)L8Norm14 Construction of the set of variables that derive terminal string. –Bottom-up flow of information Similar to the computation of nullable variables. Construction of the set of variables that are reachable –Top-down flow of information Similar to the computation of chained variables.

cs466(Prasad)L8Norm15 Examples B does not derive terminal string; C unreachable. A unreachable. Empty set of productions “Non-termination”

cs466(Prasad)L8Norm16 A CFG is in Chomsky Normal Form if each rule is of the form: Theorem: There is an algorithm to construct a grammar G’ in CNF that is equivalent to a CFG G. Chomsky Normal Form

cs466(Prasad)L8Norm17 Construction Obtain an equivalent grammar that does not contain -rules, chain rules, and useless variables. Apply following conversion on rules of the form:

cs466(Prasad)L8Norm18 Significance of CNF Length of derivation of a string of length n in CNF = (2n-1) (Cf. Number of nodes of a strictly binary tree with n-leaves) Maximum depth of a parse tree = n Minimum depth of a parse tree =

cs466(Prasad)L8Norm19 Removal of direct left recursion Causes infinite loop in top-down (depth- first) parsers. Approach: Generate string from left to right.

cs466(Prasad)L8Norm20 Note that absence of direct left recursion does not imply absence of left recursion.

cs466(Prasad)L8Norm21 (Cf. Gaussian Elimination)

cs466(Prasad)L8Norm22 Griebach Normal Form (* Constructs terminal prefixes that facilitates discovery of dead-ends *) A CFG is in Griebach Normal Form if each rule is of the form Theorem: There is an algorithm to construct a grammar G’ in GNF that is equivalent to a CFG G.

cs466(Prasad)L8Norm23 Analogy: solving linear simultaneous equations What are the values of x,y, and z? (Solving for z and then back substituiting.)

cs466(Prasad)L8Norm24 Example: conversion to GNF Eliminating left recursion Introducing terminals as first element on RHS

cs466(Prasad)L8Norm25 The size of the equivalent GNF can be large compared to the original grammar. Example CFG has 5 rules, but the corresponding GNF has 24 rules!! Length of the derivation in GNF = Length of the string. GNF is useful in relating CFGs (“generators”) to pushdown automata (“recognizers”/”acceptors”).