How to convert right linear grammar to left linear grammar?


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 → Ba

B → 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

Updated on: 14-Jun-2021

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements