Simplifies Form and Normal Form
Simplifies Form and Normal Form
Simplifies form
Context Free Grammar (CFG)
Application
• CFG are extensively used to specify the syntax of programming
language.
• CFG is used to develop parser
A → αX
Step 2:
Remove Null productions. (Using the Null production
removal algorithm discussed earlier)
Step 3:
Remove unit productions. (Using the Unit production
removal algorithm discussed earlier)
Step 4:
Remove all direct and indirect left-recursion.
Step 5:
Do proper substitutions of productions to convert it into
the proper form of GNF.
Greibach Normal Form
Example:
S → XA | BB S = A1 A1 → A2A3 | A4A4
B → b | SB X = A2 A4 → b | A1A4
X→b A = A3 A2 → b
A→a B = A4 A3 → a
Example:
A 1 → A 2A 3 | A 4A 4 First Step
A 4 → b | A 1A 4 AAii →
→ AAjjXXkk jj >> ii
A2 → b Xk is a string of zero
A3 → a
or more variables
A 4 → A 1A 4
Example:
First Step
AAii →
→ AAjjXXkk jj >> ii
A 4 → A 1A 4 A 1 → A 2A 3 | A 4A 4
A4 → A2A3A4 | A4A4A4 | b A 4 → b | A 1A 4
A4 → bA3A4 | A4A4A4 | b A2 → b
A3 → a
Example:
Left
Left Recursions
Recursions
A4 → A4A4A4
Example:
Second Step
Eliminate
Eliminate
Left
Left
Recursions
Recursions
Example:
A1 → A2A3 | A4A4
A4 → bA3A4 | b | bA3A4Z | bZ AA →
→ αX
αX
Z → A 4A 4 | A 4A 4 Z
A2 → b GNF
A3 → a
Example:
A1 → A2A3 | A4A4
A4 → bA3A4 | b | bA3A4Z | bZ
Z → A4A4 | A4A4 Z
A2 → b
A3 → a
Example:
14/11/16