Exemple #1
0
    public static void RunRegexParser(string pattern, params string[] tests)
    {
        var regex = new RegularExpression(pattern);

        if (!regex.IsValid)
        {
            Console.WriteLine($"{pattern} Is invalid.");
        }
        else
        {
            Console.WriteLine($"Pattern ({pattern}): {regex}");

            Console.WriteLine("\nNFA:");
            Console.WriteLine(regex.NFA);

            Console.WriteLine("\nDFA:");
            var dm = new TFunction(regex.NFA).ConstructDFA();
            dm.Rename();
            Console.WriteLine(dm);

            Console.WriteLine("\nMinimized DFA:");
            var diff      = dm.GetDistinguishableElements();
            var minimized = dm.Minimize(diff);
            minimized.Rename();
            Console.WriteLine(minimized);

            Console.WriteLine("\nInput Tests:");
            foreach (var test in tests)
            {
                minimized.Run(test);
            }
        }
    }
Exemple #2
0
    public static void Test()
    {
        //var file = "./demos/NFA/HW5_40";
        //var file = "./demos/NFA/Exam4";
        //var file = "./demos/NFA/HW5_36";

        /*var m = MachineUtilities.ParseFileToNFA(file);
         * var m2 = NFA.KleeneStar(m);
         *
         * Console.WriteLine("\n" + m);
         * Console.WriteLine("\n" + m2);*/

        var alph = "abcde".ToCharArray();
        var m    = NFA.GenerateFromSet("abc", alph);
        var m2   = NFA.GenerateFromString("abc", alph);

        Console.WriteLine(m + "\n");
        Console.WriteLine(m2 + "\n");

        var m3 = NFA.Plus(m);

        Console.WriteLine(m3 + "\n");

        var m4 = NFA.Plus(m2);

        Console.WriteLine(m4 + "\n");

        var dm1 = new TFunction(m3).ConstructDFA();

        Console.WriteLine(dm1 + "\n");

        var dm1m = dm1.Minimize(dm1.GetDistinguishableElements());

        dm1m.Rename();
        Console.WriteLine(dm1m + "\n");
    }