# How to convert right linear grammar to left linear grammar?

Data Structure AlgorithmsComputer ScienceComputers

For every finite automata (FA) there exists a regular grammar and for every regular grammar there is a left linear and right linear regular grammar.

## Example 1

Consider a regular grammar −

   a(a+b)*
A → aB
B → aB|bB|e

For the given regular expression, the above grammar is right linear grammar.

Now, convert the above right linear grammar to left linear grammar.

The rule to follow for conversion is,

Finite Automata → Right linear

The reverse of right linear →left linear grammar.

So,

A → BaB → Ba|Bb|e

Finally for every right linear there is a

## Example

Consider a language {bnabma| n>=2, m>=2}

The right linear grammar for the given language is −

bn ⇒ A→bA|b       A is on right side
bm ⇒ B→bB|b       B is on right side

The complete expression grammar is −

S→AaBa
A→bA|b
B→bB|b.

The left grammar for the above right linear grammar is,

bn ⇒ A→Ab|b
bm ⇒ B→Bb|b

The complete expression grammar is as follows −

S→AaBa
A→Ab|b
B→Bb|b