Пример #1
0
 public NFA Evaluate()
 {
     if (Op == RegOperation.String)
     {
         return(NFA.GenerateFromString(Content, Alphabet));
     }
     if (Op == RegOperation.Set)
     {
         return(NFA.GenerateFromSet(Content, Alphabet));
     }
     else if (Op == RegOperation.Union)
     {
         return(NFA.Union(Left.Evaluate(), Right.Evaluate()));
     }
     else if (Op == RegOperation.Concat)
     {
         return(NFA.Concat(Left.Evaluate(), Right.Evaluate()));
     }
     else if (Op == RegOperation.Star)
     {
         return(NFA.KleeneStar(Left.Evaluate()));
     }
     else if (Op == RegOperation.Plus)
     {
         return(NFA.Plus(Left.Evaluate()));
     }
     else if (Op == RegOperation.Group || Op == RegOperation.NonGroup)
     {
         return(Left.Evaluate());
     }
     else
     {
         return(null);
     }
 }
Пример #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");
    }