public static List <RegexStruct> GetRegexs() { var listStruct = new List <RegexStruct>(); var a = new RegExp("a"); var b = new RegExp("b"); var int1 = "aba(a*|b*)* begint met aba"; var reg1 = a.dot(b).dot(a).dot(a.or(b).star()); var reg2 = new RegExp("a").dot(new RegExp("a").star()).dot(new RegExp("b").dot(new RegExp("b").star())); var reg3 = new RegExp("a").or(new RegExp("b")); var reg4 = new RegExp("a").plus().dot(new RegExp("a").star()).dot(new RegExp("b").plus()); var reg5 = new RegExp("a").dot(new RegExp("a").star()).dot(new RegExp("b").dot(new RegExp("b").star())); listStruct.Add(new RegexStruct { text = int1, regex = reg1 }); listStruct.Add(new RegexStruct { regex = reg2, text = "a+b+" }); listStruct.Add(new RegexStruct { regex = reg3.star(), text = "(a|b)*" }); listStruct.Add(new RegexStruct { regex = reg4, text = "a+(a*)b+" }); listStruct.Add(new RegexStruct { regex = reg5, text = "a a* b b*" }); return(listStruct); }
public static void TestRegToAutomaat() { //(a|b)* var regex = new RegExp("a"); regex = regex.or(new RegExp("b")); regex = regex.star(); TestRegex(regex); //((ab))+ regex = new RegExp("a"); regex = regex.dot(new RegExp("b")); regex = regex.plus(); TestRegex(regex); //((a|b)|(a|d)) RegExp rA, rB, rC, rD, reg; rA = new RegExp("a"); rB = new RegExp("b"); rC = new RegExp("c"); rD = new RegExp("d"); reg = rA.or(rB); reg = reg.or(rC.or(rD)); TestRegex(reg); }
static void TestRegToDfa() { //reg: a|b var reg = new RegExp("a").or(new RegExp("b")); reg = reg.star(); Console.WriteLine(reg.ToString()); var ndfa = Thompson.CreateAutomaat(reg); var dfa = NdfatoDfa.MakeDfa(ndfa); dfa.PrintTransitions(); Console.WriteLine("reversed dfa"); var reversedDfa = dfa.Reverse(); reversedDfa.PrintTransitions(); }