Ejemplo n.º 1
0
            private void HandleSubInput(int index)
            {
                var running  = true;
                var automaat = automates[index].automaat;

                while (running)
                {
                    Console.Clear();
                    Console.WriteLine($"Gekozen {automates[index].text}");
                    subsubtext.ToList().ForEach(s => Console.WriteLine(s));
                    int input = GetInput(subsubtext.Length);
                    switch (input)
                    {
                    case 0:
                        Graphviz.PrintGraph(automaat, "test");
                        break;

                    case 1:
                        var gram = RegGram <int> .NdfaToRegGram(automaat);

                        Console.WriteLine(gram.ToString());
                        Console.ReadLine();
                        break;

                    case 2:
                        running = false;
                        automates.Clear();
                        break;
                    }
                }
            }
Ejemplo n.º 2
0
        private static void GramToNdfaAndReverse()
        {
            char[] alphabet = { 'a', 'b' };
            var    ndfa     = new Automaat <int>(alphabet);

            ndfa.AddTransition(new Transition <int>(0, alphabet[0], 0));
            ndfa.AddTransition(new Transition <int>(0, alphabet[0], 1));
            ndfa.AddTransition(new Transition <int>(0, alphabet[1], 0));
            ndfa.AddTransition(new Transition <int>(0, alphabet[1], 3));

            ndfa.AddTransition(new Transition <int>(1, alphabet[0], 2));

            ndfa.AddTransition(new Transition <int>(2, alphabet[0]));
            ndfa.AddTransition(new Transition <int>(2, alphabet[1]));

            ndfa.AddTransition(new Transition <int>(3, alphabet[1], 4));

            ndfa.AddTransition(new Transition <int>(4, alphabet[0]));
            ndfa.AddTransition(new Transition <int>(4, alphabet[1]));

            ndfa.DefineAsStartState(0);

            ndfa.DefineAsFinalState(2);
            ndfa.DefineAsFinalState(4);

            Graphviz.PrintGraph(ndfa, "ndfaToGram");

            var gram = RegGram <int> .NdfaToRegGram(ndfa);

            Console.WriteLine(gram.ToString());
        }
Ejemplo n.º 3
0
        public TestRegGram()
        {
            //Als N = { S, A }
            //    $ = { a, b }
            //P = { S -> bS, S -> aA, A -> bA, A -> b }
            //Dan is G = (N, $, P, S) een grammatica.

            char[] alphabet = { 'a', 'b' };
            var    RegGram  = new RegGram <string>(alphabet);

            RegGram.DefineStartSymbol("S");

            RegGram.AddProductionRule(new PRule <string>("S", alphabet[1], "S"));
            RegGram.AddProductionRule(new PRule <string>("S", alphabet[0], "A"));

            RegGram.AddProductionRule(new PRule <string>("A", alphabet[1], "A"));
            RegGram.AddProductionRule(new PRule <string>("A", alphabet[1]));

            Console.WriteLine(RegGram.ToString());
        }
Ejemplo n.º 4
0
        public static RegGram <T> NdfaToRegGram(Automaat <T> ndfa)
        {
            var regGram = new RegGram <T>(ndfa.GetAlphabet());

            foreach (var trans in ndfa._transitions)
            {
                regGram.AddProductionRule(new PRule <T>(trans.FromState, trans.Symbol, trans.ToState));
                if (ndfa._finalStates.Contains(trans.ToState))
                {
                    regGram.AddProductionRule(new PRule <T>(trans.FromState, trans.Symbol)
                    {
                        ToSymbolIsFinalSymbol = true
                    });
                }
            }

            regGram.DefineStartSymbol(ndfa._startStates.First());


            return(regGram);
        }