Chomsky and Greibach Normal Forms. Chomsky and Greibach Normal Forms p.1/24

Similar documents
Computer Architecture Syllabus of Qualifying Examination

Model 2.4 Faculty member + student

SRM UNIVERSITY FACULTY OF ENGINEERING & TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF SOFTWARE ENGINEERING COURSE PLAN

Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, School of Informatics University of Edinburgh als@inf.ed.ac.

Overview of E0222: Automata and Computability

Philadelphia University Faculty of Information Technology Department of Computer Science First Semester, 2007/2008.

Notes on Complexity Theory Last updated: August, Lecture 1

The Halting Problem is Undecidable

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Fast nondeterministic recognition of context-free languages using two queues

Regular Languages and Finite Automata

Finite Automata and Formal Languages

Push-down Automata and Context-free Grammars

THEORY of COMPUTATION

Introduction to Automata Theory. Reading: Chapter 1

9.2 Summation Notation

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

Honors Class (Foundations of) Informatics. Tom Verhoeff. Department of Mathematics & Computer Science Software Engineering & Technology

Pushdown Automata. International PhD School in Formal Languages and Applications Rovira i Virgili University Tarragona, Spain

Introduction to Theory of Computation

Converting Finite Automata to Regular Expressions

Basic Parsing Algorithms Chart Parsing

ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 15 april Master Edition

CHAPTER 7 GENERAL PROOF SYSTEMS

Ambiguity, closure properties, Overview of ambiguity, and Chomsky s standard form

CS 301 Course Information

Formal Grammars and Languages

Irrational Numbers. A. Rational Numbers 1. Before we discuss irrational numbers, it would probably be a good idea to define rational numbers.

Grammars and Parsing. 2. A finite nonterminal alphabet N. Symbols in this alphabet are variables of the grammar.

As we have seen, there is a close connection between Legendre symbols of the form

24 Uses of Turing Machines

Syntaktická analýza. Ján Šturc. Zima 208

Lecture 5 Principal Minors and the Hessian

CS5236 Advanced Automata Theory

Chapter 7 Uncomputability

Introduction. W. Buszkowski Type Logics in Grammar

5.5. Solving linear systems by the elimination method

Implementation of Recursively Enumerable Languages using Universal Turing Machine in JFLAP

Full and Complete Binary Trees

Computability Theory

Notes on Determinant

Math Circle Beginners Group October 18, 2015

On String Languages Generated by Spiking Neural P Systems

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy

CS 341: Foundations of Computer Science II elearning Section Syllabus, Spring 2015

Factorizations: Searching for Factor Strings

Incenter Circumcenter

Automata Theory. Şubat 2006 Tuğrul Yılmaz Ankara Üniversitesi

26 Integers: Multiplication, Division, and Order

Scanner. tokens scanner parser IR. source code. errors

FIRST and FOLLOW sets a necessary preliminary to constructing the LL(1) parsing table

Computer Science Theory. From the course description:

If n is odd, then 3n + 7 is even.

3515ICT Theory of Computation Turing Machines

Regular Expressions and Automata using Haskell

SIMPLIFYING ALGEBRAIC FRACTIONS

Math/Stats 425 Introduction to Probability. 1. Uncertainty and the axioms of probability

Lecture 9 - Message Authentication Codes

So let us begin our quest to find the holy grail of real analysis.

Lecture summary for Theory of Computation

Unit 3 Boolean Algebra (Continued)

Automata and Computability. Solutions to Exercises

Automated Program Behavior Analysis

JUST THE MATHS UNIT NUMBER 1.8. ALGEBRA 8 (Polynomials) A.J.Hobson

Continued Fractions and the Euclidean Algorithm

Bottom-Up Parsing. An Introductory Example

All the examples in this worksheet and all the answers to questions are available as answer sheets or videos.

Sequentially Indexed Grammars

Automata and Formal Languages

03 - Lexical Analysis

Parsing Beyond Context-Free Grammars: Introduction

Automatic Generation of Consistency-Preserving Edit Operations for MDE Tools

Parsing Technology and its role in Legacy Modernization. A Metaware White Paper

LZ77. Example 2.10: Let T = badadadabaab and assume d max and l max are large. phrase b a d adadab aa b

Architectural Design Patterns for Language Parsers

HOMEWORK 5 SOLUTIONS. n!f n (1) lim. ln x n! + xn x. 1 = G n 1 (x). (2) k + 1 n. (n 1)!

CHAPTER 2. Logic. 1. Logic Definitions. Notation: Variables are used to represent propositions. The most common variables used are p, q, and r.

Numeracy Preparation Guide. for the. VETASSESS Test for Certificate IV in Nursing (Enrolled / Division 2 Nursing) course

Turing Machines: An Introduction

People have thought about, and defined, probability in different ways. important to note the consequences of the definition:

3. Mathematical Induction

In mathematics, there are four attainment targets: using and applying mathematics; number and algebra; shape, space and measures, and handling data.

Approximating Context-Free Grammars for Parsing and Verification

Automated Induction with Constrained Tree Automata,

How To Understand The Theory Of Computer Science

Lemma 5.2. Let S be a set. (1) Let f and g be two permutations of S. Then the composition of f and g is a permutation of S.

The Theory of Languages and Computation

6.3 Conditional Probability and Independence

FROM NUMERICAL EQUIVALENCE TO ALGEBRAIC EQUIVALENCE 1. Rolene Liebenberg, Marlene Sasman and Alwyn Olivier

SYMBOL AND MEANING IN MATHEMATICS

Section 1.4 Place Value Systems of Numeration in Other Bases

Basics of Counting. The product rule. Product rule example. 22C:19, Chapter 6 Hantao Zhang. Sample question. Total is 18 * 325 = 5850

Transcription:

Chomsky and Greibach Normal Forms Chomsky and Greibach Normal Forms p.1/24

Simplifying a CFG It is often convenient to simplify CFG Chomsky and Greibach Normal Forms p.2/24

Simplifying a CFG It is often convenient to simplify CFG One of the simplest and most useful simplified forms of CFG is called the Chomsky normal form Chomsky and Greibach Normal Forms p.2/24

Simplifying a CFG It is often convenient to simplify CFG One of the simplest and most useful simplified forms of CFG is called the Chomsky normal form Another normal form usually used in algebraic specifications is Greibach normal form Chomsky and Greibach Normal Forms p.2/24

Simplifying a CFG It is often convenient to simplify CFG One of the simplest and most useful simplified forms of CFG is called the Chomsky normal form Another normal form usually used in algebraic specifications is Greibach normal form Note the difference between grammar cleaning and simplification Chomsky and Greibach Normal Forms p.2/24

Note Normal forms are useful when more advanced topics in computation theory are approached, as we shall see further Chomsky and Greibach Normal Forms p.3/24

Definition A context-free grammar every rule is of the form: is in Chomsky normal form if where is a terminal, are nonterminals, and may not be the start variable (the axiom) Chomsky and Greibach Normal Forms p.4/24

Note The rule, where is the start variable, is not excluded from a CFG in Chomsky normal form. Chomsky and Greibach Normal Forms p.5/24

Theorem 2.9 Any context-free language is generated by a context-free grammar in Chomsky normal form. Chomsky and Greibach Normal Forms p.6/24

Theorem 2.9 Any context-free language is generated by a context-free grammar in Chomsky normal form. Proof idea: Chomsky and Greibach Normal Forms p.6/24

Theorem 2.9 Any context-free language is generated by a context-free grammar in Chomsky normal form. Proof idea: Show that any CFG Chomsky normal form can be converted into a CFG in Chomsky and Greibach Normal Forms p.6/24

Theorem 2.9 Any context-free language is generated by a context-free grammar in Chomsky normal form. Proof idea: Show that any CFG Chomsky normal form can be converted into a CFG in Conversion procedure has several stages where the rules that violate Chomsky normal form conditions are replaced with equivalent rules that satisfy these conditions Chomsky and Greibach Normal Forms p.6/24

Theorem 2.9 Any context-free language is generated by a context-free grammar in Chomsky normal form. Proof idea: Show that any CFG Chomsky normal form can be converted into a CFG in Conversion procedure has several stages where the rules that violate Chomsky normal form conditions are replaced with equivalent rules that satisfy these conditions Order of transformations: (1) add a new start variable, (2) eliminate all -rules, (3) eliminate unit-rules, (4) convert other rules Chomsky and Greibach Normal Forms p.6/24

Theorem 2.9 Any context-free language is generated by a context-free grammar in Chomsky normal form. Proof idea: Show that any CFG Chomsky normal form can be converted into a CFG in Conversion procedure has several stages where the rules that violate Chomsky normal form conditions are replaced with equivalent rules that satisfy these conditions Order of transformations: (1) add a new start variable, (2) eliminate all -rules, (3) eliminate unit-rules, (4) convert other rules Check that the obtained CFG defines the same language Chomsky and Greibach Normal Forms p.6/24

Proof Let be the original CFG. Chomsky and Greibach Normal Forms p.7/24

Proof Let be the original CFG. Step 1: add a new start symbol to, and the rule to Chomsky and Greibach Normal Forms p.7/24

Proof Let be the original CFG. Step 1: add a new start symbol to, and the rule to Note: this change guarantees that the start symbol of does not occur on the of any rule Chomsky and Greibach Normal Forms p.7/24

Step 2: eliminate -rules Repeat 1. Eliminate the rule from where is not the start symbol 2. For each occurrence of on the with that occurrence of deleted Example: replace by replace by of a rule, add a new rule to ; 3. Replace the rule, (if it is present) by rule has been previously eliminated unless the until all rules are eliminated Chomsky and Greibach Normal Forms p.8/24

Step 3: remove unit rules Repeat 1. Remove a unit rule 2. For each rule, add the rule was a unit rule previously removed until all unit rules are eliminated to, unless Note: is a string of variables and terminals Chomsky and Greibach Normal Forms p.9/24

Convert all remaining rules Repeat 1. Replace a rule,, where each is a variable or a terminal, by:,,, where,,, are new variables,, 2. If rule replace any terminal with a new variable and add the until no rules of the form with remain Chomsky and Greibach Normal Forms p.10/24

Convert all remaining rules Repeat 1. Replace a rule,, where each is a variable or a terminal, by:,,, where,,, are new variables,, 2. If rule replace any terminal with a new variable and add the until no rules of the form with remain Chomsky and Greibach Normal Forms p.10/24

Convert all remaining rules Repeat 1. Replace a rule,, where each is a variable or a terminal, by:,,, where,,, are new variables,, 2. If rule replace any terminal with a new variable and add the until no rules of the form with remain Chomsky and Greibach Normal Forms p.10/24

Example CFG conversion Consider the grammar whose rules are: Notation: symbols removed are green and those added are red. After first step of transformation we get: Chomsky and Greibach Normal Forms p.11/24

Example CFG conversion Consider the grammar whose rules are: Notation: symbols removed are green and those added are red. After first step of transformation we get: Chomsky and Greibach Normal Forms p.11/24

Example CFG conversion Consider the grammar whose rules are: Notation: symbols removed are green and those added are red. After first step of transformation we get: Chomsky and Greibach Normal Forms p.11/24

Chomsky and Greibach Normal Forms p.12/24 Removing rules : Removing : Removing

Chomsky and Greibach Normal Forms p.12/24 Removing rules : Removing : Removing

Chomsky and Greibach Normal Forms p.12/24 Removing rules : Removing : Removing

Removing unit rule Removing : Removing : Chomsky and Greibach Normal Forms p.13/24

Removing unit rule Removing : Removing : Chomsky and Greibach Normal Forms p.13/24

Removing unit rule Removing : Removing : Chomsky and Greibach Normal Forms p.13/24

More unit rules Removing : Removing : Chomsky and Greibach Normal Forms p.14/24

More unit rules Removing : Removing : Chomsky and Greibach Normal Forms p.14/24

More unit rules Removing : Removing : Chomsky and Greibach Normal Forms p.14/24

Converting remaining rules Chomsky and Greibach Normal Forms p.15/24

Converting remaining rules Chomsky and Greibach Normal Forms p.15/24

Converting remaining rules Chomsky and Greibach Normal Forms p.15/24

Note The conversion procedure produces several variables along with several rules. Since all these represent the same rule, we may simplify the result using a single variable and a single rule Chomsky and Greibach Normal Forms p.16/24

Note The conversion procedure produces several variables along with several rules. Since all these represent the same rule, we may simplify the result using a single variable and a single rule Chomsky and Greibach Normal Forms p.16/24

Note The conversion procedure produces several variables along with several rules. Since all these represent the same rule, we may simplify the result using a single variable and a single rule Chomsky and Greibach Normal Forms p.16/24

Greibach Normal Form A context-free grammar Greibach normal form if each rule property:,,. is in has the and Note: Greibach normal form provides a justification of operator prefix-notation usually employed in algebra. Chomsky and Greibach Normal Forms p.17/24

Greibach Normal Form A context-free grammar Greibach normal form if each rule property:,,. is in has the and Note: Greibach normal form provides a justification of operator prefix-notation usually employed in algebra. Chomsky and Greibach Normal Forms p.17/24

Greibach Normal Form A context-free grammar Greibach normal form if each rule property:,,. is in has the and Note: Greibach normal form provides a justification of operator prefix-notation usually employed in algebra. Chomsky and Greibach Normal Forms p.17/24

Greibach Theorem Every CFL where can be generated by a CFG in Greibach normal form. Proof idea: Let is in Chomsky normal form be a CFG generating. Assume that Let be an ordering of nonterminals. Construct the Greibach normal form from Chomsky normal form Chomsky and Greibach Normal Forms p.18/24

Greibach Theorem Every CFL where can be generated by a CFG in Greibach normal form. Proof idea: Let is in Chomsky normal form be a CFG generating. Assume that Let be an ordering of nonterminals. Construct the Greibach normal form from Chomsky normal form Chomsky and Greibach Normal Forms p.18/24

Greibach Theorem Every CFL where can be generated by a CFG in Greibach normal form. Proof idea: Let is in Chomsky normal form be a CFG generating. Assume that Let be an ordering of nonterminals. Construct the Greibach normal form from Chomsky normal form Chomsky and Greibach Normal Forms p.18/24

Construction 1. Modify the rules in so that if then 2. Starting with and proceeding to this is done as follows: (a) Assume that productions have been modified so that for, only if (b) If is a production with productions substituting for the production, generate a new set of the rhs of each (c) Repeating (b) at most, times we obtain rules of the form (d) Replace rules by removing left-recursive rules Chomsky and Greibach Normal Forms p.19/24

Construction 1. Modify the rules in so that if then 2. Starting with and proceeding to this is done as follows: (a) Assume that productions have been modified so that for, only if (b) If is a production with productions substituting for the production, generate a new set of the rhs of each (c) Repeating (b) at most, times we obtain rules of the form (d) Replace rules by removing left-recursive rules Chomsky and Greibach Normal Forms p.19/24

Construction 1. Modify the rules in so that if then 2. Starting with and proceeding to this is done as follows: (a) Assume that productions have been modified so that for, only if (b) If is a production with productions substituting for the production, generate a new set of the rhs of each (c) Repeating (b) at most, times we obtain rules of the form (d) Replace rules by removing left-recursive rules Chomsky and Greibach Normal Forms p.19/24

Removing left-recursion Left-recursion can be eliminated by the following scheme: If nonterminal, say left recursive rules, and are all remaining -rules then chose a new are all Add the new -rules, Replace the -rules by, This construction preserve the language. Chomsky and Greibach Normal Forms p.20/24

Removing left-recursion Left-recursion can be eliminated by the following scheme: If nonterminal, say left recursive rules, and are all remaining -rules then chose a new are all Add the new -rules, Replace the -rules by, This construction preserve the language. Chomsky and Greibach Normal Forms p.20/24

Removing left-recursion Left-recursion can be eliminated by the following scheme: If nonterminal, say left recursive rules, and are all remaining -rules then chose a new are all Add the new -rules, Replace the -rules by, This construction preserve the language. Chomsky and Greibach Normal Forms p.20/24

21-1

More on Greibach NF See Introduction to Automata Theory, Languages, and Computation, J.E, Hopcroft and J.D Ullman, Addison-Wesley 1979, p. 94 96 Chomsky and Greibach Normal Forms p.22/24

Chomsky and Greibach Normal Forms p.23/24 Example Convert the CFG where into Greibach normal form.

Chomsky and Greibach Normal Forms p.23/24 Example Convert the CFG where into Greibach normal form.

Chomsky and Greibach Normal Forms p.23/24 Example Convert the CFG where into Greibach normal form.

Solution 1. Step 1: ordering the rules: (Only rules violate ordering conditions, hence only rules need to be changed). Following the procedure we replace rules by: 2. Eliminating left-recursion we get:, 3. All rules start with a terminal. We use them to replace. This introduces the rules 4. Use production to make them start with a terminal Chomsky and Greibach Normal Forms p.24/24

Solution 1. Step 1: ordering the rules: (Only rules violate ordering conditions, hence only rules need to be changed). Following the procedure we replace rules by: 2. Eliminating left-recursion we get:, 3. All rules start with a terminal. We use them to replace. This introduces the rules 4. Use production to make them start with a terminal Chomsky and Greibach Normal Forms p.24/24

Solution 1. Step 1: ordering the rules: (Only rules violate ordering conditions, hence only rules need to be changed). Following the procedure we replace rules by: 2. Eliminating left-recursion we get:, 3. All rules start with a terminal. We use them to replace. This introduces the rules 4. Use production to make them start with a terminal Chomsky and Greibach Normal Forms p.24/24