public static void Build() { short num3; NumberSet nFAList = new NumberSet(new int[0]); NumberSet set2 = new NumberSet(new int[0]); Notify.Started("Computing DFA States"); SetupForNFA(); BuilderApp.Mode = BuilderApp.ProgramMode.BuildingNFA; short num5 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1); for (num3 = 0; num3 <= num5; num3 = (short)(num3 + 1)) { SymbolBuild sym = BuilderApp.BuildTables.Symbol[num3]; if (sym.UsesDFA) { Notify.Text = sym.Name; CreateNFAStates(sym); } } BuilderApp.Mode = BuilderApp.ProgramMode.NFAClosure; short num6 = (short)(NFA.Count - 1); for (num3 = 0; num3 <= num6; num3 = (short)(num3 + 1)) { NumberSet reachable = new NumberSet(new int[0]); reachable.Add(new int[] { num3 }); ClosureNFA(reachable); NFA[num3].NFAClosure = reachable; } BuilderApp.BuildTables.CharSet.Clear(); if (NFA.Count <= 1) { BuilderApp.Log.Add(SysLogSection.DFA, SysLogAlert.Critical, "There are no terminals in the grammar"); } else { short num2; BuilderApp.Log.Add(SysLogSection.DFA, SysLogAlert.Detail, "The initial Nondeterministic Finite Automata has " + Conversions.ToString(NFA.Count) + " states"); BuilderApp.BuildTables.DFA.Clear(); BuilderApp.Mode = BuilderApp.ProgramMode.NFACase; SetupMapCaseCharTables(BuilderApp.BuildTables.Properties["Case Sensitive"].Value.ToUpper() == "TRUE", BuilderApp.GetParamCharMapping()); BuilderApp.Mode = BuilderApp.ProgramMode.BuildingDFA; nFAList.Add(new int[] { Root }); StartState = BuildDFAState(nFAList); short num7 = (short)(BuilderApp.BuildTables.DFA.Count - 1); for (num3 = 0; num3 <= num7; num3 = (short)(num3 + 1)) { short num8 = (short)(BuilderApp.BuildTables.DFA[num3].Edges().Count() - 1); num2 = 0; while (num2 <= num8) { FAEdgeBuild build3 = BuilderApp.BuildTables.DFA[num3].Edges()[num2]; CharacterSetBuild characters = build3.Characters; build3.Characters = characters; short num4 = BuilderApp.AddCharacterSet(characters); BuilderApp.BuildTables.DFA[num3].Edges()[num2].Characters = BuilderApp.BuildTables.CharSet[num4]; num2 = (short)(num2 + 1); } } short num9 = (short)(BuilderApp.BuildTables.DFA.Count - 1); for (num3 = 0; num3 <= num9; num3 = (short)(num3 + 1)) { FAStateBuild build = BuilderApp.BuildTables.DFA[num3]; if (build.AcceptList.Count() == 0) { build.Accept = null; } else if (build.AcceptList.Count() == 1) { build.Accept = BuilderApp.BuildTables.Symbol[build.AcceptList[0].SymbolIndex]; } else { FAAccept accept = build.AcceptList[0]; set2.Clear(); set2.Add(new int[] { accept.SymbolIndex }); short priority = accept.Priority; short num10 = (short)(build.AcceptList.Count() - 1); num2 = 1; while (num2 <= num10) { accept = build.AcceptList[num2]; if (accept.Priority == priority) { set2.Add(new int[] { accept.SymbolIndex }); } else if (accept.Priority < priority) { set2.Clear(); set2.Add(new int[] { accept.SymbolIndex }); priority = accept.Priority; } num2 = (short)(num2 + 1); } build.AcceptList.Clear(); short num11 = (short)(set2.Count() - 1); for (num2 = 0; num2 <= num11; num2 = (short)(num2 + 1)) { build.AcceptList.Add((short)set2[num2], priority); } if (set2.Count() == 1) { build.Accept = BuilderApp.BuildTables.Symbol[set2[0]]; } } } CheckErrorsDFA(); Notify.Completed("DFA States Completed"); } }
private static short BuildDFAState(NumberSet NFAList) { int num4; NumberSet nFAList = new NumberSet(new int[0]); FAStateBuild state = new FAStateBuild(); int num8 = NFAList.Count() - 1; for (num4 = 0; num4 <= num8; num4++) { state.NFAStates.UnionWith(NFA[NFAList[num4]].NFAClosure); } short num6 = DFAStateNumber(state); if (num6 == -1) { int num3; FAStateBuild build4; Notify.Counter++; num6 = AddDFAState(state); int num9 = state.NFAStates.Count() - 1; for (num4 = 0; num4 <= num9; num4++) { build4 = NFA[state.NFAStates[num4]]; int num10 = build4.AcceptList.Count() - 1; num3 = 0; while (num3 <= num10) { FAAccept item = build4.AcceptList[num3]; state.AcceptList.Add(item); num3++; } } NumberSet set2 = new NumberSet(new int[0]); FAEdgeList list = new FAEdgeList(); int num11 = state.NFAStates.Count() - 1; for (num4 = 0; num4 <= num11; num4++) { build4 = NFA[state.NFAStates[num4]]; int num12 = build4.Edges().Count() - 1; num3 = 0; while (num3 <= num12) { if (build4.Edges()[num3].Characters.Count() >= 1) { list.Add(build4.Edges()[num3]); set2.Add(new int[] { build4.Edges()[num3].Target }); } num3++; } } if (set2.Count() >= 1) { CharacterSetBuild build; FAEdgeBuild build3; CharacterSetBuild[] buildArray = new CharacterSetBuild[(set2.Count() - 1) + 1]; int num13 = set2.Count() - 1; for (num4 = 0; num4 <= num13; num4++) { Notify.Analyzed++; build = new CharacterSetBuild(); short num7 = (short)set2[num4]; int num14 = list.Count() - 1; num3 = 0; while (num3 <= num14) { build3 = (FAEdgeBuild)list[num3]; if (build3.Target == num7) { build.UnionWith(build3.Characters); } num3++; } int num15 = list.Count() - 1; for (num3 = 0; num3 <= num15; num3++) { build3 = (FAEdgeBuild)list[num3]; if (build3.Target != num7) { build.DifferenceWith(build3.Characters); } } buildArray[num4] = build; } CharacterSetBuild build5 = new CharacterSetBuild(); int num16 = list.Count() - 1; num3 = 0; while (num3 <= num16) { build5.UnionWith(list[num3].Characters); num3++; } int num17 = set2.Count() - 1; for (num4 = 0; num4 <= num17; num4++) { build5.DifferenceWith(buildArray[num4]); } int num18 = set2.Count() - 1; for (num4 = 0; num4 <= num18; num4++) { if (buildArray[num4].Count() >= 1) { nFAList = new NumberSet(new int[0]); nFAList.Add(new int[] { set2[num4] }); Notify.Analyzed++; state.AddEdge(buildArray[num4], BuildDFAState(nFAList)); } } int num19 = build5.Count() - 1; for (num4 = 0; num4 <= num19; num4++) { nFAList = new NumberSet(new int[0]); int number = build5[num4]; int num20 = list.Count() - 1; for (num3 = 0; num3 <= num20; num3++) { build3 = (FAEdgeBuild)list[num3]; if (build3.Characters.Contains(number)) { nFAList.Add(new int[] { build3.Target }); } } if (nFAList.Count() >= 1) { build = new CharacterSetBuild(); build.Add(new int[] { number }); Notify.Analyzed++; state.AddEdge(build, BuildDFAState(nFAList)); } } } return(num6); } return(num6); }
public CharacterSet(NumberSet CharCodes) : base(CharCodes) { }
public void Remove(NumberSet numbers) { DifferenceWith(numbers); }
public void Add(NumberSet numbers) { UnionWith(numbers); }
public int Add(NumberSet Item) { return(this.m_Array.Add(Item)); }