Presentation is loading. Please wait.

Presentation is loading. Please wait.

Context Free Grammar: Simplification

Similar presentations


Presentation on theme: "Context Free Grammar: Simplification"— Presentation transcript:

1 Context Free Grammar: Simplification
Erwin Yudi Hidayat

2 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: SAB  a Aa ???

3 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: SAB  a Aa B has no derivation...

4 D  A : causes complexity (redundant)
CFG Simplification What about this one? SA AB BC CD Da  A Lengthy path D  A : causes complexity (redundant)

5 CFG Simplification Context Free Grammar can be simplified by:
Useless production elimination Unit production elimination  production elimination

6 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.

7 Useless Production Elimination
Example: production rule in CFG is as follow: SaSa Abd  Bde AAda BBBB  a Variable A has no derivation to reach terminal As consequence, S Abd has no derivation Simplified CFG: SaSa  Bde

8 Useless Production Elimination
Example: production rule in CFG is as follow: S Aa  B Aab  D Bb  E Cbb EaEa Variable E has no derivation to reach terminal Variable D has no derivation to reach terminal Variable C never be used Simplified CFG: SAa  B Aab Bb

9 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: SSb SC CD Cef Ddd

10 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: SSb SC CD Cef Ddd

11 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: SSb SC Cdd Cef Ddd

12 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: SSb SC Cdd Cef Ddd

13 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: SSb Sdd | ef Cdd Cef Ddd

14 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: SSb Sdd | ef Cdd Cef Ddd

15 Unit Production Elimination
Ctd...

16


Download ppt "Context Free Grammar: Simplification"

Similar presentations


Ads by Google