Professional Documents
Culture Documents
13-Normal Forms For CFG - CNF and GNF-07-03-2024
13-Normal Forms For CFG - CNF and GNF-07-03-2024
13-Normal Forms For CFG - CNF and GNF-07-03-2024
GNF stands for Greibach normal form. A CFG(context free grammar) is in GNF(Greibach
normal form) if all the production rules satisfy one of the following conditions:
Problem
Convert the following CFG into CNF
𝑆 → 𝑋𝐴 | 𝐵𝐵, 𝐵 → 𝑏 | 𝑆𝐵, 𝑋 → 𝑏, 𝐴 → 𝑎
Solution
(1) If the given grammar is not in CNF, apply step 1 to step 6 to convert the
grammar in CNF.
(2) Change the Name of Non-terminal Symbols in terms of 𝐴𝑖 in ascending order of i
𝑆 → 𝑋𝐴 | 𝐵𝐵, 𝑠𝑡𝑎𝑟𝑡𝑖𝑛𝑔 𝑓𝑟𝑜𝑚 𝑠𝑡𝑎𝑟𝑡 𝑠𝑦𝑚𝑏𝑜𝑙,
𝑡ℎ𝑒𝑛 𝑛𝑎𝑚𝑒 𝑎𝑙𝑙 𝑡ℎ𝑒 𝑛𝑜𝑛𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑙𝑠 𝑓𝑟𝑜𝑚 𝑙𝑒𝑓𝑡 𝑡𝑜 𝑟𝑖𝑔ℎ𝑡, 𝑙𝑖𝑘𝑒 𝑓𝑖𝑟𝑠𝑡 𝑆, 𝑡ℎ𝑒𝑛 𝑋, 𝐴, 𝐵
𝐵 → 𝑏 | 𝑆𝐵, 𝐵, 𝑆 𝑎𝑙𝑟𝑒𝑎𝑑𝑦 𝑛𝑎𝑚𝑒𝑑 𝑠𝑜 𝑛𝑜 𝑛𝑒𝑒𝑑 𝑡𝑜 𝑛𝑎𝑚𝑒 𝑖𝑡 𝑎𝑔𝑎𝑖𝑛
𝑋 → 𝑏 , 𝑋 𝑎𝑙𝑟𝑒𝑎𝑑𝑦 𝑛𝑎𝑚𝑒𝑑 𝑠𝑜 𝑛𝑜 𝑛𝑒𝑒𝑑 𝑡𝑜 𝑛𝑎𝑚𝑒 𝑖𝑡 𝑎𝑔𝑎𝑖𝑛
𝐴 → 𝑎 , 𝐴 𝑎𝑙𝑟𝑒𝑎𝑑𝑦 𝑛𝑎𝑚𝑒𝑑 𝑠𝑜 𝑛𝑜 𝑛𝑒𝑒𝑑 𝑡𝑜 𝑛𝑎𝑚𝑒 𝑖𝑡 𝑎𝑔𝑎𝑖𝑛
S with 𝐴1
𝐴4 → 𝑏𝑍 / 𝑏𝐴3 𝐴4 𝑍
𝑍 → 𝐴4 𝐴4 𝑍/𝜀
Or
𝑨𝟒→ 𝑏𝑍 / 𝒃𝑨𝟑𝑨𝟒𝒁/𝑏 / 𝒃𝑨𝟑𝑨𝟒𝐴4 → 𝑏𝑍 / 𝑏𝐴3 𝐴4 𝑍/𝑏/ 𝑏𝐴3 𝐴4
𝑍 → 𝐴4 𝐴4 𝑍/𝐴4 𝐴4