Exemplo n.º 1
0
        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");
            }
        }