Example #1
0
        // NFA TO DFA

        public int getnotran(NFA_ nfa)
        {
            int st = 0;

            for (int i = 0; i < nfa.TS; i++)
            {
                st += nfa.TT[i].Count();
            }
            return(st);
        }
Example #2
0
        public LEVEL_1(string filename)
        {
            InitializeComponent();

            n   = g.READNFA(filename);
            dfa = n.NFAtoDFA(n);
            label_out_of.Text = n.rhymeno.ToString() + "/" + i.ToString();
            //lables title
            string tocheck = n.rhyme;

            label_search.Visible     = true;
            textBox_word.Visible     = true;
            label_correct.Visible    = true;
            label_out_of.Visible     = true;
            LABEL_SCORE.Visible      = true;
            label_score_.Visible     = true;
            label_word.Text          = tocheck;
            label_word.Visible       = true;
            label_text_enter.Visible = true;

            //tablelayoutpanel create
            tableLayoutPanel_chars.Visible   = true;
            tableLayoutPanel_chars.BackColor = Color.Moccasin;


            //lablescreated for transitions
            for (int k = 0; k < n.TS; k++)
            {
                for (int j = 0; j < n.TT[k].Count; j++)
                {
                    Label l = new Label();
                    l.BackColor = Color.Moccasin;
                    l.ForeColor = Color.Red;
                    l.Font      = new Font(new FontFamily("Showcard Gothic"), 14);
                    l.Size      = new Size(96, 60);
                    l.Location  = new Point(4, 1);
                    l.Text      = n.TT[k][j].getString().ToString();
                    l.TextAlign = ContentAlignment.MiddleCenter;
                    l.Visible   = true;

                    tableLayoutPanel_chars.Controls.Add(l);
                }
            }

            /*  for (int i = 0; i < n.rhymeno;i++ )
             * {
             *    Button button = new Button();
             *    button.BackColor = Color.Moccasin;
             *    button.ForeColor = Color.Red;
             *    button.Text = "check";
             *
             * }*/
            button_check.Visible = true;
        }
Example #3
0
        public DFA NFAtoDFA(NFA_ nfa)
        {
            List <List <int> > combinations = new List <List <int> >();
            List <int[]>       TT           = new List <int[]>();



            int s1 = nfa.IS;


            combinations.Add(new List <int>()
            {
                s1
            });
            int n        = 1;
            int addIndex = 0;

            while (n <= combinations.Count)
            {
                int[] ttArray = new int[domain.Length];
                int   i       = 0;

                foreach (char item in domain)
                {
                    List <int> tempComb = combinations[n - 1];
                    List <int> s2       = new List <int>();
                    foreach (int state in tempComb)
                    {
                        if (state != -1)
                        {
                            List <int> tempstate = nfa.getTransitoins(state, item);

                            foreach (var trans in tempstate)
                            {
                                s2.Add(trans);
                            }
                        }
                        else
                        {
                            s2.Add(-1);
                        }
                    }
                    s2.Sort();
                    s2 = s2.Distinct().ToList();

                    int index = 0;
                    if (s2.Count > 1)
                    {
                        s2.Remove(-1);
                    }
                    if (combinationExists(combinations, s2))
                    {
                        // not add
                        index        = getCombinationIndex(combinations, s2);
                        ttArray[i++] = index;
                    }
                    else
                    {
                        combinations.Add
                            (s2);
                        ttArray[i] = ++addIndex;
                        i++;
                    }
                }
                n++;
                TT.Add(ttArray);
            }


            //------------------------------Convert List to Array----------------------------------//
            int[,] finalTT = new int[TT.Count, nfa.domain.Length];
            for (int i = 0; i < finalTT.GetLength(0); i++)
            {
                for (int j = 0; j < finalTT.GetLength(1); j++)
                {
                    finalTT[i, j] = TT[i][j];
                }
            }

            //// ------------ Mark final states of new Dfa --------------------------//

            List <int> tempFs = new List <int>();

            for (int r = 0; r < combinations.Count; r++)
            {
                List <int> tempComb = combinations[r];

                foreach (var item in nfa.FS)
                {
                    if (tempComb.Contains(item))
                    {
                        tempFs.Add(r);
                    }
                }
            }
            tempFs = tempFs.Distinct().ToList();
            tempFs.Sort();

            DFA dfa3 = new DFA(0, tempFs.ToArray(), nfa.domain, finalTT);

            return(dfa3);
        }