Removal of Useless Symbols - A symbol can be useless if it does not appear on the right-hand side of the production rule and is not involved in the derivation of any string. The symbol is regarded as a symbol which is useless. Likewise, if it does not participate in the derivation of any string, a variable may be useless. That variable is called a useless symbol.
Elimination of ε Production - The Type S → ε productions are called ε productions. Only those grammars which do not produce ε can be excluded from these types of output.
Step 1: First find out all nullable non-terminal variables which derive ε.Step 2: Create all output A → x for each production A →a where x is extracted from a by removing one or more non-terminals from step 1. Step 3: Now combine with the original output the outcome of step 2 and delete ε productions.Example: Remove the production from the given CFG➔ A non-terminal generating a terminal (e.g.; X->x)
➔ A non-terminal generating two non-terminals (e.g.; X->YZ)
➔ Start symbol generating ε. (e.g.; S->ε)
Consider the following grammars,G1 = {S->a, S->AZ, A->; a, Z->z}G2 = {S->a, S->aZ, Z->a}As production rules comply with the rules defined for CNF, the grammar G1 is in CNF. However, the grammar G2 is not in CNF as the production rule S->aZ contains terminal followed by non-terminal which does not satisfy the rules specified for CNF.Key takeaway –❏ CNF is a pre-processing step used in various algorithms.
❏ For generation of string x of length ‘m’, it requires ‘2m-1’ production or steps in CNF.
Greibach Normal Form (GNF)If the productions are in the following forms, a CFG is in the Greibach Normal Form - A → bA → bD 1 …D nS → εwhere A, D 1, ...., D n are non-terminals and b is a terminal. Algorithm to Convert a CFG into Greibach Normal FormStep 1 − If the starting symbol S is on the right side, create a new starting symbol. S 'symbol and a new S'→ S output.Step 2 − Remove Null productions.Step 3 − Remove unit productions. Step 4 − Delete both left-recursion direct and indirect.Step 5 − To transform it into the proper form of GNF, make proper output substitutions. Example: Convert the following CFG into CNFS → XY | Xn | pX → mX | mY → Xn | o Sol:Here, S does not appear on the right side of any production and in the production rule collection, there is no unit or null output. So, we'll be able to bypass step 1 to step 3.Step 4 -Now after replacingX in S → XY | Xo | pwithmX | mwe obtainS → mXY | mY | mXo | mo | p.And after replacingX in Y → X n | owith the right side ofX → mX | mwe obtainY → mXn | mn | o. The production set is added to two new productions O → o and P → p and then we arrived at the final GNF as the following - S → mXY | mY | mXC | mC | pX → mX | mY → mXD | mD | oO → oP → p References: