Ejemplo n.º 1
0
        public static void TestMain(String[] args)
        {
            RegularExpression a      = new Literal("A");
            RegularExpression b      = new Literal("B");
            RegularExpression c      = new Literal("C");
            RegularExpression abStar = new KleeneStar(new Alternation(a, b));
            RegularExpression bb     = new Concatenation(b, b);
            RegularExpression r      = new Concatenation(abStar, new Concatenation(a, b));

            // The regular expression (a|b)*ab
            BuildAndShow("dfa1.dot", r);
            // The regular expression ((a|b)*ab)*
            BuildAndShow("dfa2.dot", new KleeneStar(r));
            // The regular expression ((a|b)*ab)((a|b)*ab)
            BuildAndShow("dfa3.dot", new Concatenation(r, r));
            // The regular expression (a|b)*abb, from ASU 1986 p 136
            BuildAndShow("dfa4.dot", new Concatenation(abStar, new Concatenation(a, bb)));
            // SML reals: sign?((digit+(\.digit+)?))([eE]sign?digit+)?
            RegularExpression d         = new Literal("digit");
            RegularExpression dPlus     = new Concatenation(d, new KleeneStar(d));
            RegularExpression s         = new Literal("sign");
            RegularExpression sOpt      = new Alternation(s, new Epsilon());
            RegularExpression dot       = new Literal(".");
            RegularExpression dotDigOpt = new Alternation(new Epsilon(), new Concatenation(dot, dPlus));
            RegularExpression mant      = new Concatenation(sOpt, new Concatenation(dPlus, dotDigOpt));
            RegularExpression e         = new Literal("e");
            RegularExpression exp       = new Alternation(new Epsilon(), new Concatenation(e, new Concatenation(sOpt, dPlus)));
            RegularExpression smlReal   = new Concatenation(mant, exp);

            BuildAndShow("dfa5.dot", smlReal);
        }
Ejemplo n.º 2
0
        static void Test2()
        {
            RegularExpression a     = new Literal("A");
            RegularExpression d     = new Literal("D");
            RegularExpression n     = new Literal("N");
            RegularExpression e     = new Literal("E");
            RegularExpression r     = new Literal("R");
            RegularExpression o     = new Literal("O");
            RegularExpression t     = new Literal("T");
            RegularExpression comma = new Literal(",");

            //RegularExpression notComma = new Alternation(a, d, n, e, r, o, t);
            RegularExpression notComma     = new Literal("ADNEROT");
            RegularExpression notCommaStar = new Concatenation(notComma, new KleeneStar(notComma));
            RegularExpression and          = new Concatenation(a, n, d);
            RegularExpression near         = new Concatenation(n, e, a, r);
            RegularExpression not          = new Concatenation(n, o, t);
            RegularExpression or           = new Concatenation(o, r);

            RegularExpression blah = new Alternation(near, not, and, or, comma, notCommaStar);

            Nfa nfa = blah.MakeNfa(new Nfa.NameSource());

            Console.WriteLine(nfa);
            Console.WriteLine("-------------------------------");
            Dfa dfa = nfa.ToDfa();

            Console.WriteLine(dfa);
            dfa.WriteDot("lol.dot");
        }