private static void TestRegExAndThompson() { RegExpTest ret = new RegExpTest(); ret.testLanguage(); ret.testToString(); RegExp regExp1 = new RegExp("baa"); RegExp regExp2 = new RegExp("aba"); RegExp regExp3 = new RegExp("bb"); RegExp oneOrTwo = regExp1.Or(regExp2); RegExp orStar = oneOrTwo.Star(); RegExp orStarDotThree = orStar.Dot(regExp3); RegExp orStarDotThreePlus = orStarDotThree.Plus(); Console.WriteLine("-----------------------------------------"); Console.WriteLine("And conversion by use of the thompson construction:"); Console.WriteLine("-----------------------------------------"); ThompsonConstruction thompson = new ThompsonConstruction(); Automata <string> thompsonNDFA = thompson.GenerateNDFA(orStarDotThreePlus); Console.WriteLine("thompsonNDFA is dfa? " + thompsonNDFA.IsDfa()); Console.WriteLine("-----------------------------------------"); thompsonNDFA.PrintTransitions(); Console.WriteLine("-----------------------------------------"); foreach (string state in thompsonNDFA.StartStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); foreach (string state in thompsonNDFA.FinalStates) { Console.WriteLine(state); } Console.WriteLine("-----------------------------------------"); Console.WriteLine("String {0} is a {1} string for Auto3.", THOMPSON_TEST_1, thompsonNDFA.IsStringAcceptable(THOMPSON_TEST_1) ? "valid" : "invalid"); Console.WriteLine("String {0} is a {1} string for Auto3.", THOMPSON_TEST_2, thompsonNDFA.IsStringAcceptable(THOMPSON_TEST_2) ? "valid" : "invalid"); Console.WriteLine("String {0} is a {1} string for Auto3.", THOMPSON_TEST_3, thompsonNDFA.IsStringAcceptable(THOMPSON_TEST_3) ? "valid" : "invalid"); Console.WriteLine("-----------------------------------------"); }
public RegExpTest() { a = new RegExp("a"); b = new RegExp("b"); // expr1: "baa" expr1 = new RegExp("baa"); // expr2: "bb" expr2 = new RegExp("bb"); // expr3: "baa | baa" expr3 = expr1.Or(expr2); // all: "(a|b)*" all = (a.Or(b)).Star(); // expr4: "(baa | baa)+" expr4 = expr3.Plus(); // expr5: "(baa | baa)+ (a|b)*" expr5 = expr4.Dot(all); }