private void HandleAction(RegexStruct regex1, RegexStruct regex2) { var running = true; while (running) { Console.Clear(); Console.WriteLine($"regex: {regex1.text} en {regex2.text} gekozen. Kies een actie"); actions.ToList().ForEach(a => Console.WriteLine(a)); int input = GetInput(actions.Length); switch (input) { case 0: NdfatoDfa.MakeDfa(Thompson.CreateAutomaat(regex1.regex)).ViewImage(); break; case 1: NdfatoDfa.MakeDfa(Thompson.CreateAutomaat(regex2.regex)).ViewImage(); break; case 2: Console.WriteLine("gelijkheid reg1 en reg2 is: " + regex1.regex.Equals(regex2.regex)); Console.WriteLine("druk op enter om door te gaan"); Console.ReadLine(); break; case 3: running = false; samples.Clear(); break; } } }
static void testEpsilonNDFA() { char[] alphabet = { 'a', 'b' }; var m = new Automaat <string>(alphabet); m.AddTransition(new Transition <string>("1", alphabet[0], "1")); m.AddTransition(new Transition <string>("1", alphabet[0], "2")); m.AddTransition(new Transition <string>("1", Transition <string> .Epsilon, "3")); m.AddTransition(new Transition <string>("2", alphabet[1], "4")); m.AddTransition(new Transition <string>("3", alphabet[1], "5")); m.DefineAsStartState("1"); m.DefineAsFinalState("5"); //woord bevat 1 b en eindigt op 1 b var testWords = new List <Tuple <string, bool> >(); testWords.Add(new Tuple <string, bool>("b", true)); testWords.Add(new Tuple <string, bool>("ab", true)); testWords.Add(new Tuple <string, bool>("a", false)); testWords.Add(new Tuple <string, bool>("bba", false)); testWords.Add(new Tuple <string, bool>("aaab", true)); //TestingAutomaat("Testing for epsilon transitions", m, testWords); var dfa = NdfatoDfa.MakeDfa(m); dfa.PrintTransitions(); TestingAutomaat("Testing for epsilon transitions", dfa, testWords); }
private void ViewActions(RegexStruct regexStruct) { var running = true; while (running) { Console.Clear(); Console.WriteLine($"regex: {regexStruct.text} gekozen. Kies een actie"); actions.ToList().ForEach(a => Console.WriteLine(a)); int input = GetInput(actions.Length); switch (input) { case 0: Thompson.CreateAutomaat(regexStruct.regex).ViewImage(); break; case 1: NdfatoDfa.MakeDfa(Thompson.CreateAutomaat(regexStruct.regex)).ViewImage(); break; case 2: NdfatoDfa.MakeDfa(Thompson.CreateAutomaat(regexStruct.regex)).MinimizeHopCroft(false).ViewImage(); break; case 3: running = false; samples.Clear(); break; } } }
private void HandleSubMenu(int index, Automaat <int> automaat) { switch (index) { case 0: automaat.ViewImage(); break; case 1: NdfatoDfa.MakeDfa(automaat).ViewImage(); break; case 2: automaat.MinimizeHopCroft(false).ViewImage(); break; case 3: automaat.GeefTaal(5).ForEach(s => Console.WriteLine(s)); Console.ReadLine(); break; case 4: automaat.GeefNietTaal(5).ForEach(s => Console.WriteLine(s)); Console.ReadLine(); break; } }
public Automaat <int> MinimizeReverse() { var automate = NdfatoDfa.MakeDfa(Reverse()); automate = NdfatoDfa.MakeDfa(automate.Reverse()); return(automate); }
public override bool Equals(object obj) { var reg = (RegExp)obj; if (reg == null) { return(false); } var automate1 = NdfatoDfa.MakeDfa(Thompson.CreateAutomaat(this)).MinimizeHopCroft(false); var automate2 = NdfatoDfa.MakeDfa(Thompson.CreateAutomaat(reg)).MinimizeHopCroft(false); return(automate1.Equals(automate2)); }
public void ViewImage(bool minimizedDFA) { var a = Thompson.CreateAutomaat(this); if (minimizedDFA) { Graphviz.PrintGraph(NdfatoDfa.MakeDfa(a).MinimizeReverse(), "test"); } else { Graphviz.PrintGraph(a, "test"); } }
public Automaat <int> MinimizeHopCroft(bool printTable) { var newAutomaat = NdfatoDfa.MakeDfa(this); RemoveStates(); var table = new Table(newAutomaat); table.Minimize(); if (printTable) { table.Print(); } return(table.ToAutomaat()); }
private void HandleSubInput(AutomateStruct automate) { var dfa = NdfatoDfa.MakeDfa(automate.automaat); bool running = true; while (running) { Console.Clear(); Console.WriteLine($"gekozen: {automate.text} \n"); subsubtext.ToList().ForEach(s => Console.WriteLine(s)); int input = GetInput(subsubtext.Length); switch (input) { case 0: Graphviz.PrintGraph(automate.automaat, "test"); break; case 1: Graphviz.PrintGraph(dfa, "test"); break; case 2: Graphviz.PrintGraph(dfa.MinimizeHopCroft(false), "test"); break; case 3: Console.WriteLine($"typ woord: \ntoegestane symbolen: "); automate.automaat._symbols.ToList().ForEach(c => Console.WriteLine(c)); var woord = Console.ReadLine(); if (NdfatoDfa.MakeDfa(automate.automaat).Accepteer(woord)) { Console.WriteLine("Het ingevoerde woord wordt geaccepteerd door het automaat"); } else { Console.WriteLine("Het ingevoerde woord wordt niet geaccepteerd door het automaat"); } Console.ReadLine(); break; case 4: running = false; automates.Clear(); break; } } }
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(); }
static void DfaToDfa() { //eindigd op 'aa' char[] alphabet = { 'a', 'b' }; var m = new Automaat <int>(alphabet); m.AddTransition(new Transition <int>(1, alphabet[0], 2)); m.AddTransition(new Transition <int>(1, alphabet[1], 1)); m.AddTransition(new Transition <int>(2, alphabet[0], 3)); m.AddTransition(new Transition <int>(2, alphabet[1], 1)); m.AddTransition(new Transition <int>(3, alphabet[0], 3)); m.AddTransition(new Transition <int>(3, alphabet[1], 1)); m.DefineAsStartState(1); m.DefineAsFinalState(3); NdfatoDfa.MakeDfa(m); }
static void NdfaToDfa() { char[] alphabet = { 'a', 'b' }; var m = new Automaat <int>(alphabet); m.AddTransition(new Transition <int>(0, Transition <int> .Epsilon, 1)); m.AddTransition(new Transition <int>(0, Transition <int> .Epsilon, 7)); m.AddTransition(new Transition <int>(1, Transition <int> .Epsilon, 2)); m.AddTransition(new Transition <int>(1, Transition <int> .Epsilon, 4)); m.AddTransition(new Transition <int>(2, alphabet[0], 3)); m.AddTransition(new Transition <int>(3, Transition <int> .Epsilon, 6)); m.AddTransition(new Transition <int>(4, alphabet[1], 5)); m.AddTransition(new Transition <int>(5, Transition <int> .Epsilon, 6)); m.AddTransition(new Transition <int>(6, Transition <int> .Epsilon, 7)); m.AddTransition(new Transition <int>(6, Transition <int> .Epsilon, 1)); m.AddTransition(new Transition <int>(7, alphabet[0], 8)); m.AddTransition(new Transition <int>(8, alphabet[1], 9)); m.AddTransition(new Transition <int>(9, alphabet[1], 10)); m.DefineAsStartState(0); m.DefineAsFinalState(10); var dfa = NdfatoDfa.MakeDfa(m); Graphviz.PrintGraph(m, "test"); dfa.PrintTransitions(); }