0
1.3kviews
Convert the following grammar to GNF

S => XA | BB

B => b | SB

X => b

A => a

1 Answer
0
13views

SOLUTION:

Step 1: Rename variables

Let S be A1A1, X be A2A2, A be A3A3 and B be A4A4

Therefore, the grammar now becomes

A1=>A2A3 | A4A4A1=>A2A3 | A4A4

A4=>b | A1A4A4=>b | A1A4

A2=>bA2=>b

A3=>aA3=>a

Step 2 : For each Ai=>AjAi=>Aj, ensure i <= j

This is not satisfied by A4=>A1A4A4=>A1A4

Replace A1=>A4A4A1=>A4A4

Hence, we get

A4=>A4A4A4|bA4=>A4A4A4|b

Step 3: Remove left recursion, which is not satisfied by A4=>A4A4A4A4=>A4A4A4

Let B4=>A4A4A4 | A4A4A4B4B4=>A4A4A4 | A4A4A4B4

Therefore, we get

A4=>bB4A4=>bB4

So left recursion has been removed

Step 4: Get all productions into GNF

Consider B4=>A4A4A4 | A4A4A4B4B4=>A4A4A4 | A4A4A4B4

Replacing A4=>bB4A4=>bB4 , which is already in GNF, we get

B4=>bB4A4A4A4 | bB4A4A4B4B4=>bB4A4A4A4 | bB4A4A4B4, which is now in GNF

The remaining productions are already in GNF

Please log in to add an answer.