Ejemplo n.º 1
0
        private void NFAToDFA(char[] ch)
        {
            if (READFILE == false)
            {
                NormalToNFA(ch);
            }

            CloseSet C  = new CloseSet();
            TSet     T0 = new TSet();
            //T0.tSet.Add(NFAb);
            List <int> t = new List <int>();

            t.Add(NFAb);
            T0 = E_Closure(t);

            T0.tSet.Sort();
            //T0.Unrepeated();
            C.CSet.Add(T0);



            while (C.Check() != true)
            {
                int  order = C.Sign();
                TSet Ta    = new TSet();
                TSet Tb    = new TSet();

                List <TSet> Tedges = new List <TSet>();

                TSet T = new TSet();
                /*-------------------------------------------------------------------------*/
                for (int i = 0; i < C.CSet[order].tSet.Count; i++)
                {
                    T.tSet.Add(C.CSet[order].tSet[i]);
                }

                for (int i = 0; i < transymbol.Count; i++)
                {
                    TSet temp = E_Closure(Move(T, transymbol[i]));
                    temp.tSet.Sort();
                    Tedges.Add(temp);
                }

                for (int i = 0; i < transymbol.Count; i++)
                {
                    if (C.JoinNew(Tedges[i]) == -1)
                    {
                        C.CSet.Add(Tedges[i]);
                        C.CSet[order].next[i] = C.CSet.Count - 1;
                    }
                    else
                    {
                        C.CSet[order].next[i] = C.JoinNew(Tedges[i]);
                    }
                }
            }

            MFAset = C;
            DFAes.Add(MFAset.CSet.Count - 1);
            DFA = MakeDFAcell(C);

            cell   result = DFA;
            string output = null;

            output = output + "开始状态    接受符号    到达状态\n";
            for (int i = 0; i < result.EdgeCount; i++)
            {
                string s = String.Format("{0,-12}{1,-12}{2,-12}\n", result.EdgeSet[i].StartState.StateName, result.EdgeSet[i].TransSymbol, result.EdgeSet[i].EndState.StateName);
                output = output + s;
            }

            richTextBox2.Text = output;

            DFAb          = DFA.StartState.StateName;
            DFAe          = DFA.EndState.StateName;
            textBox4.Text = DFAb.ToString();
            textBox5.Text = DFAe.ToString();

            if (READFILE == false)
            {
                textBox5.Text = DFAe.ToString();
            }
            else
            {
                List <int> ends = new List <int>();
                DFAes = ends;
                for (int i = 0; i < C.CSet.Count; i++)
                {
                    if (C.CSet[i].tSet.Contains(NFAe) == true)
                    {
                        ends.Add(i);
                    }
                }
                string d = String.Join(",", ends.ToArray());
                textBox5.Text = d;
            }
        }
Ejemplo n.º 2
0
        private void NFAToDFA(char[] ch)
        {
            NormalToNFA(ch);
            CloseSet C  = new CloseSet();
            TSet     T0 = new TSet();
            //T0.tSet.Add(NFAb);
            List <int> t = new List <int>();

            t.Add(NFAb);
            T0 = E_Closure(t);

            T0.tSet.Sort();
            //T0.Unrepeated();
            C.CSet.Add(T0);



            while (C.Check() != true)
            {
                int  order = C.Sign();
                TSet Ta    = new TSet();
                TSet Tb    = new TSet();

                List <TSet> Tedges = new List <TSet>();

                TSet T = new TSet();
                /*-------------------------------------------------------------------------*/
                for (int i = 0; i < C.CSet[order].tSet.Count; i++)
                {
                    T.tSet.Add(C.CSet[order].tSet[i]);
                }

                for (int i = 0; i < transymbol.Count; i++)
                {
                    TSet temp = E_Closure(Move(T, transymbol[i]));
                    temp.tSet.Sort();
                    Tedges.Add(temp);
                }

                for (int i = 0; i < transymbol.Count; i++)
                {
                    if (C.JoinNew(Tedges[i]) == -1)
                    {
                        C.CSet.Add(Tedges[i]);
                        C.CSet[order].next[i] = C.CSet.Count - 1;
                    }
                    else
                    {
                        C.CSet[order].next[i] = C.JoinNew(Tedges[i]);
                    }
                }
                /*-------------------------------------------------------------------------*/
                //Ta = E_Closure(Move(T,'a'));
                //Tb = E_Closure(Move(T,'b'));
                //Ta.tSet.Sort();
                //Tb.tSet.Sort();

                //if (C.JoinNew(Ta) == -1)
                //{
                //    C.CSet.Add(Ta);
                //    C.CSet[order].anext = C.CSet.Count-1;
                //}
                //else
                //{
                //    C.CSet[order].anext = C.JoinNew(Ta);
                //}
                //if (C.JoinNew(Tb) == -1)
                //{

                //    C.CSet.Add(Tb);
                //    C.CSet[order].bnext = C.CSet.Count - 1;
                //}
                //else
                //{
                //    C.CSet[order].bnext = C.JoinNew(Tb);
                //}
                /*-------------------------------------------------------------------------*/
            }

            MFAset = C;
            DFA    = MakeDFAcell(C);

            cell   result = DFA;
            string output = null;

            output = output + "开始状态    接受符号    到达状态\n";
            for (int i = 0; i < result.EdgeCount; i++)
            {
                string s = String.Format("{0,-12}{1,-12}{2,-12}\n", result.EdgeSet[i].StartState.StateName, result.EdgeSet[i].TransSymbol, result.EdgeSet[i].EndState.StateName);
                output = output + s;
            }

            richTextBox2.Text = output;

            DFAb          = DFA.StartState.StateName;
            DFAe          = DFA.EndState.StateName;
            textBox4.Text = DFAb.ToString();
            textBox5.Text = DFAe.ToString();
        }