Beispiel #1
0
        private static void Example2()
        {
            var nfa = new AutomataBuilder()
                      .SetStates(new string[] { "q0", "q1", "q2" })
                      .SetInputSymbols(new char[] { 'a', 'b', '$' })
                      .SetTransitionFunction(new string[] {
                "f(q0,a)=q1",
                "f(q0,$)=q1",
                "f(q1,a)=q0",
                "f(q1,b)=q1",
                "f(q1,a)=q2",
                "f(q1,b)=q2",
                "f(q2,a)=q2",
                "f(q2,b)=q1",
                "f(q2,b)=q1",
            })
                      .SetInitialState("q0")
                      .SetFinalState("q1")
                      .Build();

            Console.WriteLine("=== NFA Primitive Infomation ===");
            Console.WriteLine(nfa.About());
            Console.WriteLine("Epsilon Closures: ");
            foreach (var state in nfa.States)
            {
                var eclosure = nfa.GetEpsilonClosureOf(state);
                Console.WriteLine("{0}: {{{1}}}", state, string.Join(',', eclosure));
            }

            var transitionFunctions = new HashSet <TransitionFunction>();

            foreach (var state in nfa.States)
            {
                var eclosure = nfa.GetEpsilonClosureOf(state);
                foreach (var eclosureState in eclosure)
                {
                    var acceptableInputs = nfa.GetAcceptableInputOf(eclosureState, true);
                    foreach (var input in acceptableInputs)
                    {
                        var func = (new TransitionFunction(eclosure, input, nfa.GetNextStatesOf(eclosure, input)));
                        transitionFunctions.Add(func);
                    }
                }
            }
            Console.WriteLine("New transition functions:");
            Console.WriteLine(string.Join("\n", transitionFunctions));
        }
Beispiel #2
0
        private static void Example1()
        {
            var nfa = new AutomataBuilder()
                      .SetStates(new string[] { "A", "B", "C", "D", "E" })
                      .SetInputSymbols(new char[] { '0', '1', '$' })
                      .SetTransitionFunction(new string[] {
                "f(A,0)=B",
                "f(A,$)=C",
                "f(B,$)=D",
                "f(C,$)=D",
                "f(C,1)=E",
                "f(D,0)=D",
                "f(D,1)=E",
            })
                      .SetInitialState("A")
                      .SetFinalState("E")
                      .Build();

            Console.WriteLine("=== NFA Primitive Infomation ===");
            Console.WriteLine(nfa.About());
            Console.WriteLine("Epsilon Closures: ");
            foreach (var state in nfa.States)
            {
                var eclosure = nfa.GetEpsilonClosureOf(state);
                Console.WriteLine("{0}: {{{1}}}", state, string.Join(',', eclosure));
            }

            var transitionFunctions = new SortedSet <TransitionFunction>();

            foreach (var state in nfa.States)
            {
                var eclosure = nfa.GetEpsilonClosureOf(state);
                foreach (var eclosureState in eclosure)
                {
                    var acceptableInputs = nfa.GetAcceptableInputOf(eclosureState, true);
                    foreach (var input in acceptableInputs)
                    {
                        var func = (new TransitionFunction(eclosure, input, nfa.GetNextStatesOf(eclosure, input)));
                        transitionFunctions.Add(func);
                    }
                }
            }
            Console.WriteLine("New transition functions:");
            Console.WriteLine(string.Join("\n", transitionFunctions));
        }