public static void Main(string[] args) { NodeDFA q1 = new NodeDFA(nameof(q1), false); NodeDFA q2 = new NodeDFA(nameof(q2), false); NodeDFA q3 = new NodeDFA(nameof(q3), true); NodeDFA q4 = new NodeDFA(nameof(q4), false); NodeDFA q5 = new NodeDFA(nameof(q5), true); string[] alphabet = { "0", "1" }; q1.Build(alphabet, q4, q2); q2.Build(alphabet, q3, q1); q3.Build(alphabet, q3, q1); q4.Build(alphabet, q4, q5); q5.Build(alphabet, q4, q4); var automata = new DFA(alphabet, q1); automata.Print(); automata.PrintIsAccepted("0111"); }
public bool IsWordAccepted(string word) { var splitWord = SplitWord(word); if (!CheckWord(splitWord)) { return(false); } NodeDFA node = StartingNode as NodeDFA; var road = node.Name; for (int i = 0; i < splitWord.Length; ++i) { if (!node.CheckConnections(Alphabet)) { return(false); } road += " --" + splitWord[i] + "--> "; node = node.Associations[splitWord[i]]; road += node.Name; } road += Environment.NewLine; Console.WriteLine(road); if (node.IsAccepting) { return(true); } return(false); }
public void ConnectWith(NodeDFA node, string symbol) { Associations.Add(symbol, node); }
public DFA(IEnumerable <string> alphabet, NodeDFA startingNode) : base(alphabet, startingNode) { }