CNF-PPT-CS5800 - Department of Computer Science

Report
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 nonterminal symbols, α is a terminal symbol, S is
the start symbol, and ε is the empty string.
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.
• 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.
EXAMPLE : IN CFG
S -> S1 | S2
S1 -> S1b | Ab
S2 -> S2a | Ba
A -> aAb | ab | ε
B -> bBa | ba | ε
CONVERTED TO CNF
A -> aA1 | ab
A1 -> Ab
B -> bB1 | ba
B1 -> Ba
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.
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.
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.
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.
• 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.
REFERENCE
• Languages and Machines: An Introduction to t
he 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.
THANK YOU

similar documents