private static void CreateStatesSymbolsAndSymbolPaths( IGrammar grammar, out Dictionary <IProduction, Dictionary <int, DottedRule> > states, out Dictionary <ISymbol, UniqueList <ISymbol> > symbolPaths) { states = new Dictionary <IProduction, Dictionary <int, DottedRule> >(); symbolPaths = new Dictionary <ISymbol, UniqueList <ISymbol> >(); for (var p = 0; p < grammar.Productions.Count; p++) { var production = grammar.Productions[p]; var stateIndex = states.AddOrGetExisting(production); var leftHandSide = production.LeftHandSide; var symbolPath = symbolPaths.AddOrGetExisting(leftHandSide); for (var s = 0; s <= production.RightHandSide.Count; s++) { var preComputedState = new DottedRule(production, s); stateIndex.Add(s, preComputedState); if (s < production.RightHandSide.Count) { var postDotSymbol = production.RightHandSide[s]; symbolPath.AddUnique(postDotSymbol); } } } }
public GrammarSeededDottedRuleRegistry(IGrammar grammar) { for (var p = 0; p < grammar.Productions.Count; p++) { var production = grammar.Productions[p]; for (var s = 0; s <= production.RightHandSide.Count; s++) { var dottedRule = new DottedRule(production, s); Register(dottedRule); } } }
public bool Contains(DottedRule state) { return(_set.Contains(state)); }
private void RegisterDottedRule(IProduction production, int s) { var dottedRule = new DottedRule(production, s); _dottedRuleRegistry.Register(dottedRule); }
private static bool IsComplete(DottedRule state) { return(state.Position == state.Production.RightHandSide.Count); }
private static ISymbol GetPostDotSymbol(DottedRule state) { return(state.Production.RightHandSide[state.Position]); }