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 production must start with a single terminal followed by any number of variables.

A Context Free Grammar (CFG) is in Greibach Normal Form, if the production rules are in the following form

A -> a
A -> aB1, B2………Bn

In this where A, B1………Bn are any number of non-terminals, and a is a terminal used in Greibach Normal Form.

Example of Greibach Normal Form:

A -> bBC
B -> a

In this, A, B,C are non-terminals and a,b is a terminal

Steps to convert Context Free Grammar to Greibach Normal Form (GNF)

  • Check, if the given Context Free Grammar has any Unit productions or Null productions, and remove those Unit productions or Null productions.
  • Check whether the given Context Free Grammar is already in Chomsky Normal Form, and convert into Chomsky Normal Form, if it is not.
  • In this step, we have all the productions in the form some Ai where Ai is in ascending order of i.
  • In this step, we modify all the productions of the form Ai -> Aj X, then i < j and it should never be i >= j.
  • In this step, we remove all left Recursion in production rules.

Example:

Convert the following Context Free Grammar to Greibach Normal Form (GNF)

S -> CA

S -> BB

B -> b

B -> SB

A -> a

Solution:

Step 1:

In above given production rules there are no unit production and null production so, no need to perform the step1.

Step 2:

In step 2, the given grammar is already in Chomsky Normal form, so we can skip this step.

Step 3:

In this step we have all the productions in the form some Ai where Ai is in ascending order of i.

Replace S variable with A1

Replace C variable with A2

Replace A variable with A3

Replace B variable with A4

After replacing the symbol using Ai where i is 1 to 4 we get the new production rules as:

A1 -> A2A3 | A4A4

A4 -> b | A1A4

A2 -> b

A3 -> a

Step 4:

In this step, we modify all the productions of the form Ai -> Aj X, then i < j, and should never be i >= j.

where Ai  = A1 (L.H.S) and Aj = A2 (R.H.S)

For 1st production:

 A1 -> A2A3 | A4A4

1 < 2 i.e. ( i < j)

1 < 4 i.e. ( i < j) it follows the step 4

For 2nd production:

A4 -> b | A1A4

As we know, if non-terminal symbol directly gives the terminal symbol, then it is already in Greibach Normal Form (GNF)

Now second part i.e. A1A4

4 > 1 i.e. ( i > j)

A4 -> b | A1A4

A4 -> b | A2A3 A4 |A4 A4 A4        [Replace     A4 A4       with A1] 

Now, see whether they follow the rule or not.

I = 4 , j = 2

i > j [Not follow]

A4 -> b | A2A3 A4 |A4A4A4       

A4 -> b | A2A3 A4 |A4A4A4        [again A2 create problem]

A4 -> b | bA3 A4 |A4A4A4       [bA3 A4 this part in GNF]

Now check the third half i.e. A4A4A4      

In this part we get i = j (i.e. 4 = 4)     

 A4 -> b | bA3 A4 |A4A4A4 [first A4 is left recursive]

According to the rule of GNF, if non-terminal symbol is followed by terminal symbol and further that terminal is followed by any other non-terminal symbol, then it is in GNF.

Step 5:

In this step we remove a left Recursion. Introduce a new variable to remove the left recursion.

A4 -> b | bA3 A4 |A4A4A4     

[This is a problem here, we don’t have variable or terminal symbol]

Introduce the new variable = Z, to remove the left recursion.

A4 -> b | bA3 A4 |A4A4A4      

Z -> A4A4Z | A4A4       

A4 -> b | bA3 A4 |bZ| bA3 A4 Z

Now, the new grammar is:

A1 -> A2A3 | A4A4

A4 -> b | bA3 A4 | bZ | bA3A4Z

Z -> A4A4 | A4A4Z

A2 -> b

A3 -> a

In A1 -> A2A3

In GNF, we don’t allow to have a variable in the beginning, so, we remove A2 variable with b terminal in the beginning.

A4 -> bA3 |bA4 | bA3 A4A4 | bZA4 | bA3 A4Z
 A4 -> b|bA3A4 |bZ | bA3 A4Z
 Z -> bA4|bA3A4A4 |bZA4 | bA3 A4ZA4 | bA4Z | bA3A4A4Z | bZA4Z | bA3A4ZA4Z
 A2 -> b //Already in GNF
 A3 -> a //Already in GNF 

In this way, we successfully have completed our conversion and the grammar we have is successfully converted into Greibach Normal Form.


Related Topics

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Minimization of Finite Automata

Minimization of Finite Automata The term minimization refers to the construction of finite automata with a minimum number of states, which is equivalent to the given finite automata. The number of...

4 minutes read.

Conversion from NFA to DFA

Conversion from NFA to DFA A Non-deterministic Finite Automata (NFA) is a finite state machine, in which, the move from one state to another is not fully deterministic, i.e., for a...

4 minutes read.

What is Automata Theory?

What is Automata Theory? Automata theory is used to study the abstract machine and automata (the self-acting machine).  Abstract machine is a theoretical model of a computer used in Automata theory. Automata...

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

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.

Conversion from Mealy Machine to Moore Machine

Conversion from Mealy Machine to Moore Machine In this topic, we will see different ways that are used for the conversion of Mealy Machine to Moore Machine. Moore Machine The output of Moore...

4 minutes read.