Context Free Grammar: Simplification Erwin Yudi Hidayat erwin@dsn.dinus.ac.id
CFG Simplification Purpose: to limit or minimize complexity in parsing a tree due to unnecessary production rule Example: production rule in CFG is defined as follow: SAB a Aa ???
CFG Simplification Purpose: to limit or minimize complexity in parsing a tree due to unnecessary production rule Example: production rule in CFG is defined as follow: SAB a Aa B has no derivation...
D A : causes complexity (redundant) CFG Simplification What about this one? SA AB BC CD Da A Lengthy path D A : causes complexity (redundant)
CFG Simplification Context Free Grammar can be simplified by: Useless production elimination Unit production elimination production elimination
Useless Production Elimination Useless production is defined as: Any production contains variable which has no derivation to produce terminals. This production is useless as endless derivation (variable symbol still remains) Any production that never can be reached using any derivation from start symbol, therefore this production is redundant.
Useless Production Elimination Example: production rule in CFG is as follow: SaSa Abd Bde AAda BBBB a Variable A has no derivation to reach terminal As consequence, S Abd has no derivation Simplified CFG: SaSa Bde
Useless Production Elimination Example: production rule in CFG is as follow: S Aa B Aab D Bb E Cbb EaEa Variable E has no derivation to reach terminal Variable D has no derivation to reach terminal Variable C never be used Simplified CFG: SAa B Aab Bb
Unit Production Elimination Unit production is defined as any production that consist only one single variable symbol, e.g. A B, C D Example: production rule in CFG is as follow: SSb SC CD Cef Ddd
Unit Production Elimination Unit production is defined as any production that consist only one single variable symbol, e.g. A B, C D Example: production rule in CFG is as follow: SSb SC CD Cef Ddd
Unit Production Elimination Unit production is defined as any production that consist only one single variable symbol, e.g. A B, C D Example: production rule in CFG is as follow: SSb SC Cdd Cef Ddd
Unit Production Elimination Unit production is defined as any production that consist only one single variable symbol, e.g. A B, C D Example: production rule in CFG is as follow: SSb SC Cdd Cef Ddd
Unit Production Elimination Unit production is defined as any production that consist only one single variable symbol, e.g. A B, C D Example: production rule in CFG is as follow: SSb Sdd | ef Cdd Cef Ddd
Unit Production Elimination Unit production is defined as any production that consist only one single variable symbol, e.g. A B, C D Example: production rule after simplification: SSb Sdd | ef Cdd Cef Ddd
Unit Production Elimination Ctd...