コード例 #1
0
ファイル: Program.cs プロジェクト: nbirillo/Studying
        public static void Test3()
        {
            int k = 3;

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

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

            Pair<char, string> p1 = new Pair<char, string>('S', "aB");
            Pair<char, string> p2 = new Pair<char, string>('S', "bA");
            Pair<char, string> p3 = new Pair<char, string>('A', "a");
            Pair<char, string> p4 = new Pair<char, string>('B', "b");
            Pair<char, string> p5 = new Pair<char, string>('A', "bAA");
            Pair<char, string> p6 = new Pair<char, string>('B', "aBB");
            Pair<char, string> p7 = new Pair<char, string>('A', "aS");
            Pair<char, string> p8 = new Pair<char, string>('B', "bS");

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

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

            f.Output_Grammar();
            Console.WriteLine();
            f.Output_FIRST();
        }
コード例 #2
0
ファイル: first_window.cs プロジェクト: nbirillo/Studying
        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;
        }