public static void SaveAsRangeAutomaton(string regex, BitWidth encoding, string file, bool epsilonfree = false, bool determinize = false, int determinization_timeout_ms = 0) { var solver = new CharRangeSolver(encoding); var converter = new RegexToAutomatonConverterRanges(solver); var A = converter.Convert(regex, System.Text.RegularExpressions.RegexOptions.None); if (epsilonfree) { A = A.RemoveEpsilons(solver.MkOr); } if (determinize) { A = A.RemoveEpsilons(solver.MkOr); A.CheckDeterminism(solver); A = A.Determinize(solver, determinization_timeout_ms); } //A.CheckDeterminism(solver,true); //if (!A.isDeterministic) // throw new AutomataException(AutomataExceptionKind.InternalError); System.IO.StreamWriter sw = new System.IO.StreamWriter(file); sw.WriteLine(A.InitialState); foreach (var s in A.GetFinalStates()) { sw.Write("{0} ", s); } sw.WriteLine(); foreach (var move in A.GetMoves()) { if (move.IsEpsilon) { sw.WriteLine("{0} {1} {2} {3}", move.SourceState, -1, -1, move.TargetState); } else { foreach (var range in move.Label) { sw.WriteLine("{0} {1} {2} {3}", move.SourceState, (int)range.First, (int)range.Second, move.TargetState); } } } sw.Close(); }
public static void SaveAsRangeAutomaton(string regex, BitWidth encoding, string file, bool epsilonfree = false, bool determinize = false, int determinization_timeout_ms = 0) { var solver = new CharRangeSolver(encoding); var converter = new RegexToAutomatonConverterRanges(solver); var A = converter.Convert(regex, System.Text.RegularExpressions.RegexOptions.None); if (epsilonfree) A = A.RemoveEpsilons(); if (determinize) { A = A.RemoveEpsilons(); A.CheckDeterminism(); A = A.Determinize(determinization_timeout_ms); } //A.CheckDeterminism(solver,true); //if (!A.isDeterministic) // throw new AutomataException(AutomataExceptionKind.InternalError); System.IO.StreamWriter sw = new System.IO.StreamWriter(file); sw.WriteLine(A.InitialState); foreach (var s in A.GetFinalStates()) sw.Write("{0} ", s); sw.WriteLine(); foreach (var move in A.GetMoves()) if (move.IsEpsilon) sw.WriteLine("{0} {1} {2} {3}", move.SourceState, -1, -1, move.TargetState); else foreach (var range in move.Label) sw.WriteLine("{0} {1} {2} {3}", move.SourceState, (int)range.First, (int)range.Second, move.TargetState); sw.Close(); }