C# Class CFGLib.CFGtoCNF

A class to help transform a generic grammar into a CNF grammar
Show file Open project: ellisonch/CFGLib Class Usage Examples

Private Methods

Method Description
CFGtoCNF ( Grammar grammar ) : System
Convert ( ) : CNFGrammar

Actually performs the conversion and returns a new CNF grammar based on the old grammar

GetFresh ( ) : Nonterminal
GetProbability ( Production production, Dictionary productionsByNonterminal ) : double
MergeProductions ( Production>.Dictionary results, IEnumerable toAdd ) : void
Nullate ( Production originalProduction, double>.Dictionary nullableProbabilities ) : List

From a production, derive a set of productions for each combination of skipping nullable nonterminals. E.g., for production S -> AbB and nullable {A, B}, we get productions S -> AbB | Ab | bB | b

RemoveExtraneousNulls ( List productions ) : void

Remove <A> -> ε unless A is the start symbol

RemoveSelfLoops ( ISet productions ) : void
RemoveUnits ( IEnumerable productions ) : IEnumerable
StepBin ( ISet productions ) : void

Eliminate right-hand sides with more than 2 nonterminals

StepDel ( ISet productions ) : void

Eliminate ε-rules

StepStart ( ISet productions ) : void

Eliminate the start symbol from right-hand sides

StepTerm ( ISet productions ) : void

Eliminate rules with nonsolitary terminals

StepUnit ( ISet productions ) : void

Eliminate unit rules (e.g., <X> -> <Y>)

UnitReplacementProductions ( Production unitProduction, Dictionary productionsByNonterminal ) : IEnumerable