private void EpsilonNotNull(NodeNFA node, string[] splitWord, string road) { foreach (var newNode in node.EpsilonPath) { var wordList = new List <string>(splitWord).GetRange(0, splitWord.Length); IsWordAccepted(string.Concat(wordList), newNode, road + " --eps--> "); } }
private void IsWordAccepted(string word, NodeNFA startingNode, string road = "") { var splitWord = SplitWord(word); if (!CheckWord(splitWord)) { return; } NodeNFA node = startingNode; road += node.Name; if (!node.CheckConnections(Alphabet)) { return; } if (node.EpsilonPath != null) { EpsilonNotNull(node, splitWord, road); } if (word.Length == 0) { if (node.IsAccepting) { road += " | ACCEPTED"; } else { road += " | NOT ACCEPTED"; } Console.WriteLine(road); return; } if (node.Associations[splitWord[0]] == null) { road += " --" + splitWord[0] + "--> null | NULL END"; Console.WriteLine(road); return; } var nodes = node.Associations[splitWord[0]]; foreach (var newNode in nodes) { var wordList = new List <string>(splitWord).GetRange(1, splitWord.Length - 1); IsWordAccepted(string.Concat(wordList), newNode, road + " --" + splitWord[0] + "--> "); } }
public static void Main(string[] args) { NodeNFA q1 = new NodeNFA(nameof(q1), false); NodeNFA q2 = new NodeNFA(nameof(q2), true); NodeNFA q3 = new NodeNFA(nameof(q3), false); string[] alphabet = { "a", "b" }; q1.Build(alphabet, new[] { q2, q3 }, null); q2.Build(alphabet, null, new[] { q2, q3 }, new[] { q1 }); q3.Build(alphabet, new[] { q2 }, null); var automata = new NFA(alphabet, q1); automata.Print(); Console.WriteLine(); automata.RemoveEpsilonPasses().Print(); Console.WriteLine(); automata.ToDFA().Print(); //automata.PrintIsAccepted("ababb"); }
public NFA(IEnumerable <string> alphabet, NodeNFA startingNode) : base(alphabet, startingNode) { }