Ejemplo n.º 1
0
        private void FirstButton_Click(object sender, EventArgs e)
        {
            string[] allStrings = inputTextBox.Text.Split(new char[2] {
                '\r', '\n'
            }, StringSplitOptions.RemoveEmptyEntries);
            SortedSet <string> N = new SortedSet <string>(allStrings[0].Split(new char[1] {
                ' '
            }, StringSplitOptions.RemoveEmptyEntries));
            SortedSet <string> T = new SortedSet <string>(allStrings[1].Split(new char[1] {
                ' '
            }, StringSplitOptions.RemoveEmptyEntries));

            T.Add("e");
            int n = Convert.ToInt32(allStrings[2]);
            Dictionary <string, List <string> > P = new Dictionary <string, List <string> >();

            for (int i = 3; i < 3 + n; i++)
            {
                string s = allStrings[i][0].ToString();
                if (!P.ContainsKey(s))
                {
                    P[s] = new List <string>();
                }
                P[s].Add(allStrings[i].Substring(3));
            }

            int    k    = Convert.ToInt32(allStrings[n + 3]);
            string line = allStrings[n + 4];

            AnswerForm F = new AnswerForm();

            F.printFirst(getFirst(N, P, k, line, getGrammaFirst(T, N, P, k)), line);
            F.Show();
        }
Ejemplo n.º 2
0
        private void plusButton_Click(object sender, EventArgs e)
        {
            string[] allStrings = inputTextBox.Text.Split(new char[2] {
                '\r', '\n'
            }, StringSplitOptions.RemoveEmptyEntries);
            SortedSet <string> L1 = new SortedSet <string>(allStrings[0].Split(new char[1] {
                ' '
            }, StringSplitOptions.RemoveEmptyEntries));
            SortedSet <string> L2 = new SortedSet <string>(allStrings[1].Split(new char[1] {
                ' '
            }, StringSplitOptions.RemoveEmptyEntries));
            int k = Convert.ToInt32(allStrings[2]);

            AnswerForm F = new AnswerForm();

            F.printPlus(getPlus(L1, L2, k));
            F.Show();
        }
Ejemplo n.º 3
0
        private void FollowButton_Click(object sender, EventArgs e)
        {
            string[] allStrings = inputTextBox.Text.Split(new char[2] {
                '\r', '\n'
            }, StringSplitOptions.RemoveEmptyEntries);
            SortedSet <string> N = new SortedSet <string>(allStrings[0].Split(new char[1] {
                ' '
            }, StringSplitOptions.RemoveEmptyEntries));
            SortedSet <string> T = new SortedSet <string>(allStrings[1].Split(new char[1] {
                ' '
            }, StringSplitOptions.RemoveEmptyEntries));

            T.Add("e");
            int n = Convert.ToInt32(allStrings[2]);
            Dictionary <string, List <string> > P = new Dictionary <string, List <string> >();

            for (int i = 3; i < 3 + n; i++)
            {
                string s = allStrings[i][0].ToString();
                if (!P.ContainsKey(s))
                {
                    P[s] = new List <string>();
                }
                P[s].Add(allStrings[i].Substring(3));
            }
            string start      = allStrings[n + 3];
            int    k          = Convert.ToInt32(allStrings[n + 4]);
            string neterminal = allStrings[n + 5];

            Dictionary <string, SortedSet <string> > gFirst = getGrammaFirst(T, N, P, k);
            Dictionary <string, Dictionary <string, SortedSet <string> > > fi = getGrammaFi_follow(N, P, k, gFirst);

            SortedSet <string> Follow = new SortedSet <string>(fi[start][neterminal]);

            if (start == neterminal)
            {
                Follow.Add("e");
            }

            AnswerForm F = new AnswerForm();

            F.printFollow(Follow, neterminal);
            F.Show();
        }