public static void PrintKernelItems <TTokenKind>( this LrItemsDfa <TTokenKind> dfa, TextWriter writer ) where TTokenKind : struct, Enum { dfa.PrintItemsHelper(writer, itemSet => itemSet.KernelItems); }
private static void PrintItemsHelper <TTokenKind>( this LrItemsDfa <TTokenKind> dfa, TextWriter writer, Func <ProductionItemSet <TTokenKind>, IEnumerable <ProductionItem <TTokenKind> > > itemsResolver ) where TTokenKind : struct, Enum { string maximalStateIndex = $"s{dfa.MaxState - 1}: "; // Trimmed states are ordered 1,2,3,...,MaxState (because we neglect the dead state at index zero) // To be consistent with dragon book we order states 0,1,2,...,MaxState-1 (as if dead state does not exist) foreach (int state in dfa.GetTrimmedStates()) { var itemSet = dfa.GetUnderlyingState(state); var items = itemsResolver(itemSet); string stateIndex = $"s{state - 1}:".PadRight(maximalStateIndex.Length); writer.Write(stateIndex); writer.WriteLine(items.First()); foreach (var kernelItem in items.Skip(1)) { writer.Write(new string(' ', maximalStateIndex.Length)); writer.WriteLine(kernelItem); } } }