/// <summary> /// Turns a <see cref="RegExp"/> into a <see cref="Automata{string}"/>, which is a NDFA. /// </summary> /// <param name="expressionToTranslate">The <see cref="RegExp"/> to translate.</param> /// <returns>A <see cref="Automata{string}"/>, which is a NDFA or null if there was a problem</returns> public Automata <string> GenerateNDFA(RegExp expressionToTranslate) { HashSet <char> alphabet = new HashSet <char>(); String regexAsString = expressionToTranslate.ToString(); foreach (char c in regexAsString) { if (IsUsableCharacter(c)) { alphabet.Add(c); } } ; ThompsonPart completeNdfaAsThompson = GenerateThompsonPart(regexAsString); if (completeNdfaAsThompson.Equals(new ThompsonPart())) { return(null); } Automata <string> NDFA = new Automata <string>(alphabet.ToArray()); foreach (Transition <string> thompsonTransition in completeNdfaAsThompson.transitions) { NDFA.AddTransition(thompsonTransition); } NDFA.DefineAsStartState(completeNdfaAsThompson.startState); NDFA.DefineAsFinalState(completeNdfaAsThompson.finalState); return(NDFA); }
public void testToString() { Console.WriteLine(expr1.ToString()); Console.WriteLine(expr2.ToString()); Console.WriteLine(expr3.ToString()); Console.WriteLine(all.ToString()); Console.WriteLine(expr4.ToString()); Console.WriteLine(expr5.ToString()); }