Chomsky's Normal Form - Automata

Chomsky's Normal Form (CNF)

In context free grammar, the left-hand side of production rules contains only one variable, and right side may contain any number of variables or terminals in production rule. The production rules in context free grammar are in the form

A -> a, where A is a variable, and a is string of any symbols from (V ? T)*

If we want to impose restriction on the right side of production rule, then context free grammar is said to be in a “normal form”.

In Chomsky Normal Form, there are restrictions on the length of right-hand side, and type of symbols is used in right hand side of production rules.

A -> BC

A -> a

In this, A, B and C are variables, and a is terminal

Steps to convert Context Free Grammar to Chomsky's Normal Form (CNF)

  • If start variable S occurs on right side of any production rule, then create a new start symbol S’, and add as a new production i.e., S’ -> S, in given production rules.
  • Remove or eliminate all Null Productions in given production rules.
  • Remove or eliminate all Unit productions in given production rules.
  • In this step, find out the productions, which have more than two variables in right hand side. Repeat this step for all productions having 2 or more symbols in right hand side.
  • If the right side of any production is of form A ->aB, where a is terminal and A, B are non-terminals, then production is replaced by A -> XB and X -> a.

Example:

Convert the following Context Free Grammar to Chomsky's Normal Form (CNF)

S -> ASA

S -> aB

A -> B

A -> S

A -> ?

B -> b

B -> ?

Solution:

Step 1: S is the start variable in any production rule. In above given production rules, S variable appears in R.H.S, then we can add a new start symbol S’ and add a new Production S’ -> S in above given production.

S’ -> S

S -> ASA

S -> aB

A -> B

A -> S

A -> ?

B -> b

B -> ?

Step 2: Remove the null productions i.e.

A -> ? and B -> ?

After removing the null productions B -> ?

S’ -> S

S -> ASA

S -> aB

S -> a

A -> B

A -> S

A -> B

A -> ?

B -> b

Now removing the null production A -> ?, and after removing the null productions A -> ?. The new production is:

S’ -> S

S -> ASA

S -> aB

S -> a

S -> AS

S -> SA

S -> S

A -> B

A -> S

B -> b

Step 3: Remove Unit productions. i.e.

S -> S

S’ -> S

A -> B

A -> S

After removing the unit production S -> S, the new production is:

S’ -> S

S -> ASA

S -> aB

S -> a

S -> AS

S -> SA

A -> B

A -> S

B -> b

After removing the unit production A -> B, the new production is:

S’ -> ASA|aB|a|AS|SA

S -> ASA|aB|a|AS|SA

A -> b|S

B -> b

After removing the unit production A -> S, the new production is:

S’ -> ASA | aB | a| AS | SA

S -> ASA | aB | a| AS | SA

A -> b ASA | aB | a| AS | SA

B -> b

Step 4: Now, find out the productions that has more than two variables in R.H.S.

S’ -> ASA

S -> ASA

A -> ASA

After removing this production, the new production we get

S’ -> AX | aB | a| AS|SA

S -> AX | aB |a |AS|SA

A -> b| AX | ASA|aB|a|AS|SA

B -> b

X -> AX

Step 5: Now change the productions:

S’ -> aB

S -> aB

A -> aB

Finally, we get the production after converting the given Context Free Grammar to Chomsky's Normal Form (CNF)

S’ -> AX | YB| aB | a| AS|SA

S -> AX | YB | aB |a |AS|SA

A -> b| AX | YB | ASA| aB |a| AS |SA

B -> b

X -> SA

Y -> a

This is the required Context Normal Form(CNF) for given Context Free Grammar (CFG).


Related Topics

Push down Automata Acceptance

Acceptance of Language by Push down Automata Push down Automata accepts the language, which is called context free language. Push down Automata = Finite Automata + Auxiliary Memory (Stack) Auxiliary Memory helps Push...

3 minutes read.

Conversion from Moore Machine to Mealy Machine

Conversion from Moore Machine to Mealy Machine Moore Machine The output of Moore machine depends only on the present state. In this, if machine has N number of states, then it will...

6 minutes read.

Automata Tutorial

What is Automata? Automata is a mathematical model and abstract model, which is used to detect string in various languages. In Automata, Regular language is recognized by Finite state AutomataContext Free language...

4 minutes read.

Equivalence of Regular Grammar and Finite Automata

Equivalence of Regular Grammar and Finite Automata Regular Grammar / type -3 grammar A regular grammar or type-3 defines the language called regular language that is accepted by finite Automata.A Regular Grammar...

3 minutes read.

Ambiguity in Context Free Grammar - Automata

Ambiguity in Context Free Grammar? Context Free Grammar Context Free Grammar has one condition for production rules, which is, on the left-hand side of each rule, there must be only single variable,...

4 minutes read.

Pumping Lemma for Regular Languages - Automata

Pumping Lemma for Regular Languages The language accepted by the finite automata is called Regular Language. If we are given a language L and asked whether it is regular or not?...

4 minutes read.

Recursive Language and Recursive Enumerable Language

Recursive Language and Recursive Enumerable Language Before discussing Recursive language and Recursive Enumerable language, let us see what Turing machine responds for some input string. If we have the Turing machine T...

4 minutes read.

Derivation Tree of Context Free Grammar - Automata

Derivation Tree of Context Free Grammar Derivation tree gives a way to show how a string can be derived from context free grammar. It is also called as parse tree, production...

3 minutes read.

Automata Greibach Normal Form

Greibach Normal Form In Greibach Normal Form, there is restriction on the position, in which, terminals and variables can appear on right-hand side of production rules. In Greibach Normal Form, every...

4 minutes read.

Simplification of Context Free Grammar - Automata

Simplification of Context Free Grammar Context Free Grammar has recursive structure. The languages that are accepted with Context Free Grammar are called Context Free Languages. Context Free Grammar has one condition...

3 minutes read.

Non-deterministic Turing Machine - Automata

A non-deterministic Turing machine (NTM) is a theoretical machine used in computability theory to study the extent to which a machine can "guess" at a solution and yet still be...

4 minutes read.

Converting Finite Automata to Regular Expression using Arden’s Theorem

Converting Finite Automata to Regular Expression using Arden’s Theorem The Arden’s Theorem can be applied to find the regular expression recognized by the given transition diagram. This theorem can be applied...

4 minutes read.

Minimization of Finite Automata with Output

Minimization of Finite Automata with Output The method to minimize the Moore and Mealy machine is very much similar to the method that we have used to minimize the DFA. Methods to...

3 minutes read.

Automata Regular Expressions

Regular Expressions Regular expressions are also referred as rational expressions, which are used to describe the algebraic description of regular languages. It is generally a sequence of characters that is used...

3 minutes read.

Chomsky's Normal Form - Automata

Chomsky's Normal Form (CNF) In context free grammar, the left-hand side of production rules contains only one variable, and right side may contain any number of variables or terminals in production...

4 minutes read.

Automata Chomsky Hierarchy

Chomsky Hierarchy Formal languages: A language with precise syntax and semantics are called formal languages. Noam Chomsky has defined the Chomsky hierarchy in 1956. He is an American scientist and philosopher, and...

3 minutes read.

Pumping Lemma for Context Free Languages

Pumping Lemma for Context Free Languages The Pumping Lemma is made up of two words, in which, the word pumping is used to generate many input strings by pushing the symbol...

3 minutes read.

Finite Automata

Finite Automata Finite state Automata or Finite State Machine is the simplest model used in Automata. Finite state automata accepts regular language. In this, the term finite means it has a...

4 minutes read.

Context Free Grammar - Automata

Context Free Grammar Grammar defines a set of rules, and with the help of these rules valid sentences in a language are constructed. A grammar consists of collection of substitution rules,...

3 minutes read.

Closure Properties of Regular Languages -Automata

Closure Properties of Regular Languages We use the term “Closure” when we talk about sets of things. If we have two regular languages L1 and L2, and L is obtained by...

3 minutes read.