Hector Miguel Chavez Western Michigan University.

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

Simplifications of Context-Free Grammars
Variations of the Turing Machine
PDAs Accept Context-Free Languages
AP STUDY SESSION 2.
1
Chapter 3 Demand and Behavior in Markets. Copyright © 2001 Addison Wesley LongmanSlide 3- 2 Figure 3.1 Optimal Consumption Bundle.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
Objectives: Generate and describe sequences. Vocabulary:
UNITED NATIONS Shipment Details Report – January 2006.
By John E. Hopcroft, Rajeev Motwani and Jeffrey D. Ullman
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
Custom Statutory Programs Chapter 3. Customary Statutory Programs and Titles 3-2 Objectives Add Local Statutory Programs Create Customer Application For.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt BlendsDigraphsShort.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
CSCI 3130: Formal Languages and Automata Theory Tutorial 5
Solve Multi-step Equations
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Break Time Remaining 10:00.
Turing Machines.
Table 12.1: Cash Flows to a Cash and Carry Trading Strategy.
PP Test Review Sections 6-1 to 6-6
Bright Futures Guidelines Priorities and Screening Tables
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
How to convert a left linear grammar to a right linear grammar
Copyright © 2013, 2009, 2006 Pearson Education, Inc. 1 Section 5.5 Dividing Polynomials Copyright © 2013, 2009, 2006 Pearson Education, Inc. 1.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
Adding Up In Chunks.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
: 3 00.
5 minutes.
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
Analyzing Genes and Genomes
1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Clock will move after 1 minute
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Physics for Scientists & Engineers, 3rd Edition
Energy Generation in Mitochondria and Chlorplasts
Select a time to count down from the clock above
Murach’s OS/390 and z/OS JCLChapter 16, Slide 1 © 2002, Mike Murach & Associates, Inc.
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
The Pumping Lemma for CFL’s
Closure Properties of CFL's
About Grammars CS 130 Theory of Computation HMU Textbook: Sec 7.1, 6.3, 5.4.
Normal forms for Context-Free Grammars
CONVERTING TO CHOMSKY NORMAL FORM
1 Context Free Grammars Xiaoyin Wang CS 5363 Spring 2016.
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
Jaya Krishna, M.Tech, Assistant Professor
7. Properties of Context-Free Languages
Context-Free Languages
Presentation transcript:

Hector Miguel Chavez Western Michigan University

Presentation Outline 2May 27, 2009 Introduction Chomsky normal form Preliminary simplifications Final steps Greibach Normal Form Algorithm (Example) Summary

Introduction 3May 27, 2009 Grammar: G = (V, T, P, S) T = { a, b } Terminals V = A, B, C Variables S S Start Symbol P = S → A Production

Introduction 4May 27, 2009 Grammar example S → aBSc S → abc Ba → aB Bb → bb L = { a n b n c n | n ≥ 1 } S aBSc aBabcc aaBbcc aabbcc

Introduction 5May 27, 2009 Context free grammar The head of any production contains only one non-terminal symbol S → P P → aPb P → ε L = { a n b n | n ≥ 0 }

Presentation Outline 6May 27, 2009 Introduction Chomsky normal form Preliminary simplifications Final simplification Greibach Normal Form Algorithm (Example) Summary

Chomsky Normal Form 7May 27, 2009 A → BC A → α A context free grammar is said to be in Chomsky Normal Form if all productions are in the following form: A, B and C are non terminal symbols α is a terminal symbol

Presentation Outline 8May 27, 2009 Introduction Chomsky normal form Preliminary simplifications Final steps Greibach Normal Form Algorithm (Example) Summary

Preliminary Simplifications 9May 27, 2009 Eliminate Useless Symbols 1 Eliminate ε productions 2 Eliminate unit productions 3 There are three preliminary simplifications

Preliminary Simplifications 10May 27, 2009 Eliminate Useless Symbols We need to determine if the symbol is useful by identifying if a symbol is generating and is reachable X is generating if X ω for some terminal string ω. X is reachable if there is a derivation X αXβ for some α and β * *

Preliminary Simplifications 11May 27, 2009 Example: Removing non-generating symbols S → AB | a A → b S → AB | a A → b Initial CFL grammar S → AB | a A → b S → AB | a A → b Identify generating symbols S → a A → b S → a A → b Remove non-generating

Preliminary Simplifications 12May 27, 2009 Example: Removing non-reachable symbols S → a Eliminate non-reachable S → a A → b S → a A → b Identify reachable symbols

Preliminary Simplifications 13May 27, 2009 The order is important. S → AB | a A → b S → AB | a A → b Looking first for non-reachable symbols and then for non-generating symbols can still leave some useless symbols. S → a A → b S → a A → b

Preliminary Simplifications 14May 27, 2009 Finding generating symbols If there is a production A → α, and every symbol of α is already known to be generating. Then A is generating S → AB | a A → b S → AB | a A → b We cannot use S → AB because B has not been established to be generating

Preliminary Simplifications 15May 27, 2009 Finding reachable symbols S is surely reachable. All symbols in the body of a production with S in the head are reachable. S → AB | a A → b S → AB | a A → b In this example the symbols {S, A, B, a, b} are reachable.

Preliminary Simplifications 16May 27, 2009 Eliminate Useless Symbols 1 Eliminate ε productions 2 Eliminate unit productions 3 There are three preliminary simplifications

Preliminary Simplifications 17May 27, 2009 Eliminate ε Productions In a grammar ε productions are convenient but not essential If L has a CFG, then L – {ε} has a CFG Nullable variable A ε *

Preliminary Simplifications 18May 27, 2009 If A is a nullable variable Whenever A appears on the body of a production A might or might not derive ε S → ASA | aB A → B | S B → b | ε Nullable: {A, B}

Preliminary Simplifications 19May 27, 2009 Create two version of the production, one with the nullable variable and one without it Eliminate productions with ε bodies S → ASA | aB A → B | S B → b | ε S → ASA | aB | AS | SA | S | a A → B | S B → b Eliminate ε Productions

Preliminary Simplifications 20May 27, 2009 Create two version of the production, one with the nullable variable and one without it Eliminate productions with ε bodies S → ASA | aB A → B | S B → b | ε S → ASA | aB | AS | SA | S | a A → B | S B → b Eliminate ε Productions

Preliminary Simplifications 21May 27, 2009 Create two version of the production, one with the nullable variable and one without it Eliminate productions with ε bodies S → ASA | aB A → B | S B → b | ε S → ASA | aB | AS | SA | S | a A → B | S B → b Eliminate ε Productions

Preliminary Simplifications 22May 27, 2009 Eliminate Useless Symbols 1 Eliminate ε productions 2 Eliminate unit productions 3 There are three preliminary simplifications

Preliminary Simplifications 23May 27, 2009 Eliminate unit productions A unit production is one of the form A → B where both A and B are variables A B * A → B, B → ω, then A → ω Identify unit pairs

Preliminary Simplifications 24May 27, 2009 Example: I → a | b | Ia | Ib | I0 | I1 F → I | (E) T → F | T * F E → T | E + T PairsProductions ( E, E )E → E + T ( E, T )E → T * F ( E, F )E → (E) ( E, I )E → a | b | Ia | Ib | I0 | I1 ( T, T )T → T * F ( T, F )T → (E) ( T, I )T → a | b | Ia |Ib | I0 | I1 ( F, F )F → (E) ( F, I )F → a | b | Ia | Ib | I0 | I1 ( I, I )I → a | b | Ia | Ib | I0 | I1 Basis: (A, A) is a unit pair of any variable A, if A A by 0 steps. * T = {*, +, (, ), a, b, 0, 1}

Preliminary Simplifications 25May 27, 2009 Example: PairsProductions …… ( T, T )T → T * F ( T, F )T → (E) ( T, I )T → a | b | Ia |Ib | I0 | I1 …… I → a | b | Ia | Ib | I0 | I1 E → E + T | T * F | (E ) | a | b | la | lb | l0 | l1 T → T * F | (E) | a | b | Ia | Ib | I0 | I1 F → (E) | a | b | Ia | Ib | I0 | I1

Presentation Outline 26May 27, 2009 Introduction Chomsky normal form Preliminary simplifications Final steps Greibach Normal Form Algorithm (Example) Summary

Final Simplification 27May 27, 2009 Chomsky Normal Form (CNF) 1.Arrange that all bodies of length 2 or more to consists only of variables. 2.Break bodies of length 3 or more into a cascade of productions, each with a body consisting of two variables. Starting with a CFL grammar with the preliminary simplifications performed

Final Simplification 28May 27, 2009 Step 1: For every terminal α that appears in a body of length 2 or more create a new variable that has only one production. E → E + T | T * F | (E ) | a | b | la | lb | l0 | l1 T → T * F | (E) | a | b | Ia | Ib | I0 | I1 F → (E) | a | b | Ia | Ib | I0 | I1 I → a | b | Ia | Ib | I0 | I1 E → EPT | TMF | LER | a | b | lA | lB | lZ | lO T → TMF | LER | a | b | IA | IB | IZ | IO F → LER | a | b | IA | IB | IZ | IO I → a | b | IA | IB | IZ | IO A → aB → bZ → 0O → 1 P → +M → *L → (R → )

Final Simplification 29May 27, 2009 Step 2: Break bodies of length 3 or more adding more variables E → EPT | TMF | LER | a | b | lA | lB | lZ | lO T → TMF | LER | a | b | IA | IB | IZ | IO F → LER | a | b | IA | IB | IZ | IO I → a | b | IA | IB | IZ | IO A → aB → bZ → 0O → 1 P → +M → *L → (R → ) C 1 → PT C 2 → MF C 3 → ER

Presentation Outline 30May 27, 2009 Introduction Chomsky normal form Preliminary simplifications Final steps Greibach Normal Form Algorithm (Example) Summary

Greibach Normal Form 31May 27, 2009 A → αX A context free grammar is said to be in Greibach Normal Form if all productions are in the following form: A is a non terminal symbols α is a terminal symbol X is a sequence of non terminal symbols. It may be empty.

Presentation Outline 32May 27, 2009 Introduction Chomsky normal form Preliminary simplifications Final steps Greibach Normal Form Algorithm (Example) Summary

Greibach Normal Form 33May 27, 2009 Example: S → XA | BB B → b | SB X → b A → a CNF S = A 1 X = A 2 A = A 3 B = A 4 New Labels A 1 → A 2 A 3 | A 4 A 4 A 4 → b | A 1 A 4 A 2 → b A 3 → a Updated CNF

Greibach Normal Form 34May 27, 2009 Example: A 1 → A 2 A 3 | A 4 A 4 A 4 → b | A 1 A 4 A 2 → b A 3 → a First Step X k is a string of zero or more variables A i → A j X k j > i A 4 → A 1 A 4

Greibach Normal Form 35May 27, 2009 Example: A 1 → A 2 A 3 | A 4 A 4 A 4 → b | A 1 A 4 A 2 → b A 3 → a A 4 → A 1 A 4 A 4 → A 2 A 3 A 4 | A 4 A 4 A 4 | b A 4 → bA 3 A 4 | A 4 A 4 A 4 | b First Step A i → A j X k j > i

Greibach Normal Form 36May 27, 2009 Example: Second Step Eliminate Left Recursions A 1 → A 2 A 3 | A 4 A 4 A 4 → bA 3 A 4 | A 4 A 4 A 4 | b A 2 → b A 3 → a A 4 → A 4 A 4 A 4

Greibach Normal Form 37May 27, 2009 Example: Second Step Eliminate Left Recursions A 1 → A 2 A 3 | A 4 A 4 A 4 → bA 3 A 4 | A 4 A 4 A 4 | b A 2 → b A 3 → a A 4 → bA 3 A 4 | b| bA 3 A 4 Z | bZ Z → A 4 A 4 | A 4 A 4 Z

Greibach Normal Form 38May 27, 2009 Example: A 1 → A 2 A 3 | A 4 A 4 A 4 → bA 3 A 4 | b | bA 3 A 4 Z | bZ Z → A 4 A 4 | A 4 A 4 Z A 2 → b A 3 → a A → αX GNF

Greibach Normal Form 39May 27, 2009 Example: A 1 → A 2 A 3 | A 4 A 4 A 4 → bA 3 A 4 | b | bA 3 A 4 Z | bZ Z → A 4 A 4 | A 4 A 4 Z A 2 → b A 3 → a Z → bA 3 A 4 A 4 | bA 4 | bA 3 A 4 ZA 4 | bZA 4 | bA 3 A 4 A 4 | bA 4 | bA 3 A 4 ZA 4 | bZA 4 A 1 → bA 3 | bA 3 A 4 A 4 | bA 4 | bA 3 A 4 ZA 4 | bZA 4

Greibach Normal Form 40May 27, 2009 Example: A 1 → bA 3 | bA 3 A 4 A 4 | bA 4 | bA 3 A 4 ZA 4 | bZA 4 A 4 → bA 3 A 4 | b | bA 3 A 4 Z | bZ Z → bA 3 A 4 A 4 | bA 4 | bA 3 A 4 ZA 4 | bZA 4 | bA 3 A 4 A 4 | bA 4 | bA 3 A 4 ZA 4 | bZA 4 A 2 → b A 3 → a Grammar in Greibach Normal Form

Presentation Outline 41May 27, 2009 Summary (Some properties) Every CFG that doesn’t generate the empty string can be simplified to the Chomsky Normal Form and Greibach Normal Form The derivation tree in a grammar in CNF is a binary tree In the GNF, a string of length n has a derivation of exactly n steps Grammars in normal form can facilitate proofs CNF is used as starting point in the algorithm CYK

Presentation Outline 42May 27, 2009 References [1] Introduction to Automata Theory, Languages and Computation, John E. Hopcroft, Rajeev Motwani and Jeffrey D. Ullman, 2nd edition, Addison Wesley 2001 (ISBN: ) [2] CS-311 HANDOUT, Greibach Normal Form (GNF), Humaira Kamal, [3] Conversion of a Chomsky Normal Form Grammar to Greibach Normal Form, Arup Guha, h.ppt

Test Questions 43May 27, Convert the following grammar to the Chomsky Normal Form. 2.Is the following grammar context-free? 3.Prove that the language L = { a n b n c n | n ≥ 1 } is not context-free. 4.Convert the following grammar to the Greibach Normal Form. S → P P → aPb | ε S → aBSc | abc Ba → aB Bb → bb S -> a | CD | CS A -> a | b | SS C -> a D -> AS

Presentation Outline 44May 27, 2009