Presentation is loading. Please wait.

Presentation is loading. Please wait.

CONVERTING TO CHOMSKY NORMAL FORM

Similar presentations


Presentation on theme: "CONVERTING TO CHOMSKY NORMAL FORM"— Presentation transcript:

1 CONVERTING TO CHOMSKY 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 € V where 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


Download ppt "CONVERTING TO CHOMSKY NORMAL FORM"

Similar presentations


Ads by Google