/// <summary> /// Compiles a pattern string produces a Minimum DFA model. /// </summary> /// <param name="sPattern">Actual pattern string in the correct format</param> /// <returns>ErrorCode indicating how the compilatio went.</returns> public ErrorCode Compile(string sPattern) { ValidationInfo vi = m_reValidator.Validate(sPattern); UpdateValidationInfo(vi); if (vi.ErrorCode != ErrorCode.ERR_SUCCESS) { return(vi.ErrorCode); } State.ResetCounter(); string sRegExConcat = vi.FormattedString; string sRegExPostfix = ConvertToPostfix(sRegExConcat); State stateStartNfa = CreateNfa(sRegExPostfix); State.ResetCounter(); State stateStartDfa = ConvertToDfa(stateStartNfa); m_stateStartDfaM = stateStartDfa; m_stateStartDfaM = ReduceDfa(stateStartDfa); return(ErrorCode.ERR_SUCCESS); }
/// <summary> /// Compiles a pattern string produces a Minimum DFA model. /// </summary> /// <param name="sPattern">Actual pattern string in the correct format</param> /// <param name="sbStats">This will receive the statistics. Can be null.</param> /// <returns>ErrorCode indicating how the compilatio went.</returns> public ErrorCode CompileWithStats(string sPattern, StringBuilder sbStats) { if (sbStats == null) { return(Compile(sPattern)); // no statistics required } State.ResetCounter(); int nLineLength = 0; ValidationInfo vi = m_reValidator.Validate(sPattern); UpdateValidationInfo(vi); if (vi.ErrorCode != ErrorCode.ERR_SUCCESS) { return(vi.ErrorCode); } //虽然注意到了connection问题,但是没想到用.号表示。 string sRegExPostfix = ConvertToPostfix(vi.FormattedString); sbStats.AppendLine("Original pattern:\t\t" + sPattern); sbStats.AppendLine("Pattern after formatting:\t" + vi.FormattedString); sbStats.AppendLine("Pattern after postfix:\t\t" + sRegExPostfix); sbStats.AppendLine(); State stateStartNfa = CreateNfa(sRegExPostfix); sbStats.AppendLine(); sbStats.AppendLine("NFA Table:"); nLineLength = GetSerializedFsa(stateStartNfa, sbStats); sbStats.AppendFormat(("").PadRight(nLineLength, '*')); sbStats.AppendLine(); State.ResetCounter(); State stateStartDfa = ConvertToDfa(stateStartNfa); sbStats.AppendLine(); sbStats.AppendLine("DFA Table:"); nLineLength = GetSerializedFsa(stateStartDfa, sbStats); sbStats.AppendFormat(("").PadRight(nLineLength, '*')); sbStats.AppendLine(); State stateStartDfaM = ReduceDfa(stateStartDfa); m_stateStartDfaM = stateStartDfaM; sbStats.AppendLine(); sbStats.AppendLine("DFA M' Table:"); nLineLength = GetSerializedFsa(stateStartDfaM, sbStats); sbStats.AppendFormat(("").PadRight(nLineLength, '*')); sbStats.AppendLine(); return(ErrorCode.ERR_SUCCESS); }