1 / 13

CONVERTING TO CHOMSKY NORMAL FORM

CONVERTING TO CHOMSKY NORMAL FORM. Darshana Chaturvedi. CHOMSKY NORMAL FORM. The CNF places constraints on the length and the composition of the right – hand side of a rule. A CFG is in CNF if each rule has one of the following forms: A → BC

shae
Download Presentation

CONVERTING TO CHOMSKY NORMAL FORM

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CONVERTING TOCHOMSKY NORMAL FORM Darshana Chaturvedi

  2. CHOMSKY NORMAL FORM • The CNF places constraints on the length and the composition of the right – hand side of a rule. A CFG is in CNF if each rule has one of the following forms: A → BC A → α S → ε where B,C € V – {S} and A,B,C are non-terminal symbols, αis a terminal symbol, S is the start symbol, and ε is the empty string.

  3. CONVERSION OF CFG INTO CNF The conversion consists of following steps: • Introduce  Sₒ such that Sₒ → S where Sₒ is the new start variable and S is the previous start variable. • Eliminate all ε rules ε  rules are rules of the form  A → ε where A ≠ Sₒ and A € Vwhere V is the CFG’s variable alphabet.

  4. Eliminate all unit rules A → B where A,B € V After all the εrules have been removed, you can be in removing unit rules. • Eliminate all useless symbols. • Clean up remaining rules that are not in Chomsky normal form.

  5. EXAMPLE : IN CFG S -> S1| S2 S1 -> S1b | Ab S2 -> S2a | Ba A -> aAb | ab | ε B -> bBa | ba | ε

  6. CONVERTED TO CNF A -> aA1 | ab A1 -> Ab B -> bB1 | ba B1 -> Ba

  7. BENEFITS • To solve elementary problems involving CFL’s. • It yields efficient algorithms. • It is used by the CYK algorithm to determine if a string is generated by CFG. • A grammar in CNF has a simple structure, and that makes it easy to parse.

  8. DESIGN FLOW • We have given CFG example files as input in our program. • The program would analyze these CFG’s. • Then it would be converted into CNF. • The program would consist of the steps to show the conversion to CNF.

  9. STRUCTURE The java program will consist of the following parts. • Class : For the internal structure of the program. It will take the input and parses as CFG and then the program will convert CFG into CNF.

  10. There would be three classes which are : • Cyk.java checkGrammar calls for the input to be read, initializes the table and fills it. The final table is then printed.

  11. Rule.java Read the input from a file and put it in the ArrayLists for processing by the algorithm. • Main.java Calls the checkGrammar function.

  12. REFERENCE • Languages and Machines: An Introduction to the Theory of Computer Science, Third Edition by Thomas A. Sudkamp. • Introduction to Automata Theory , Languages and Computation, Second Edition by John E. Hopcroft, Rajeev Motwani and Jeffrey D. Ullman.

  13. THANK YOU

More Related