converting to chomsky normal form darshana chaturvedi

13
CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

Upload: terence-allen

Post on 12-Jan-2016

226 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

CONVERTING TO CHOMSKY NORMAL

FORM

Darshana Chaturvedi

Page 2: 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

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.

Page 3: CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

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.

Page 4: CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

• 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.

 

Page 5: CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

EXAMPLE : IN CFG

S -> S1 | S2

S1 -> S1b | Ab

S2 -> S2a | Ba

A -> aAb | ab | ε

B -> bBa | ba | ε

Page 6: CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

CONVERTED TO CNF

A -> aA1 | ab

A1 -> Ab

B -> bB1 | ba

B1 -> Ba

Page 7: CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

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.

Page 8: CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

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.

 

Page 9: CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

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.

Page 10: CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

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.

Page 11: CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

• 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.

Page 12: CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

REFERENCE

• Languages and Machines: An Introduction to the Theory of Computer Science, Third Edi-tion by Thomas A. Sudkamp.

• Introduction to Automata Theory , Languages and Computation, Second Edition by John E. Hopcroft, Rajeev Motwani and Jeffrey D. Ullman.

Page 13: CONVERTING TO CHOMSKY NORMAL FORM Darshana Chaturvedi

THANK YOU