public static void Build() { short tableIndex = BuilderApp.BuildTables.StartSymbol.TableIndex; if (tableIndex == -1) { BuilderApp.Log.Add(SysLogSection.LALR, SysLogAlert.Critical, "Start symbol is invalid or missing"); } else { Notify.Started("Computing LALR Tables"); SymbolBuild build = BuilderApp.BuildTables.Symbol[tableIndex]; BuilderApp.BuildTables.LALR.Clear(); SetupTempTables(); if (build.First.Count() >= 1) { short count; bool flag; int num2; LRStateBuild build2; BuilderApp.Mode = BuilderApp.ProgramMode.BuildingLALR; Symbol startSymbol = build; build = (SymbolBuild)startSymbol; CreateLRState(CreateInitialState(startSymbol)); do { flag = true; count = (short)BuilderApp.BuildTables.LALR.Count; int num4 = count - 1; num2 = 0; while (num2 <= num4) { build2 = BuilderApp.BuildTables.LALR[num2]; if (!build2.Expanded) { flag = false; build2.Expanded = true; ComputeLRState(build2); } num2++; } }while (!flag); do { flag = true; count = (short)BuilderApp.BuildTables.LALR.Count; int num5 = count - 1; for (num2 = 0; num2 <= num5; num2++) { build2 = BuilderApp.BuildTables.LALR[num2]; if (build2.Modified) { flag = false; build2.Modified = false; RecomputeLRState(build2); } } }while (!flag); ComputeReductions(); Notify.Completed("LALR Tables Completed"); } else { BuilderApp.Log.Add(SysLogSection.LALR, SysLogAlert.Critical, "Rule <" + build.Name + "> does not produce any terminals."); } ClearTempTables(); } }
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"); } }