Пример #1
0
        public static void Test4()
        {
            int k = 2;

            HashSet<char> terms = new HashSet<char>();
            terms.Add('a');
            terms.Add('b');
            terms.Add('e');

            HashSet<char> nonTerms = new HashSet<char>();
            nonTerms.Add('S');
            nonTerms.Add('A');

            Pair<char, string> p1 = new Pair<char, string>('S', "aAaa");
            Pair<char, string> p2 = new Pair<char, string>('S', "bAba");
            Pair<char, string> p3 = new Pair<char, string>('A', "b");
            Pair<char, string> p4 = new Pair<char, string>('A', "e");

            List<Pair<char, string>> rules = new List<Pair<char, string>>();
            rules.Add(p1);
            rules.Add(p2);
            rules.Add(p3);
            rules.Add(p4);

            first_2 f = new first_2(terms, nonTerms, rules);
            f.find_FIRST();

            f.Output_Grammar();
            Console.WriteLine();
            f.Output_FIRST();
        }
Пример #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            int k = Convert.ToInt32(textBox8.Text);

            if (k <= 0 || k > 3)
            {
                string message = "Введите k = 1, 2 или 3!";
                string caption = "Неверный ввод k";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                DialogResult result;

                // Displays the MessageBox.

                result = MessageBox.Show(message, caption, buttons);
                return;
            }

            button2.Enabled = false;

            dataGridView2.Visible = true;

            HashSet<char> terms = new HashSet<char>();
            for (int i = 0; i < textBox2.Text.Length; i++)
                terms.Add(textBox2.Text[i]);

            HashSet<char> nonTerms = new HashSet<char>();
            for (int i = 0; i < textBox4.Text.Length; i++)
                nonTerms.Add(textBox4.Text[i]);

            List<Pair<char, string>> rules = new List<Pair<char, string>>();
            int countRow = Convert.ToInt32(textBox7.Text);
            for (int i = 0; i < countRow; i++)
            {
                char start = Convert.ToChar(dataGridView1[0, i].Value);
                string end = dataGridView1[1, i].Value.ToString();
                Pair<char, string> p = new Pair<char, string>(start, end);
                rules.Add(p);
            }

            switch (k)
            {
                case 1:
                    {
                        first_1 first = new first_1(terms, nonTerms, rules);
                        first.find_FIRST();
                        Output_FIRST(k, first.dic_first);
                        break;
                    }
                case 2:
                    {
                        first_2 first = new first_2(terms, nonTerms, rules);
                        first.find_FIRST();
                        Output_FIRST(k, first.dic_first);
                        break;
                    }
                case 3:
                    {
                        first_3 first = new first_3(terms, nonTerms, rules);
                        first.find_FIRST();
                        Output_FIRST(k, first.dic_first);
                        break;
                    }
                default:
                    {
                        break;
                    }
            }

            button3.Enabled = true;
        }