I'm attempting to develop from scratch a simple regex engine. I would like for my engine to have the ability to report, "The regex matched on a substring of this line starting at index and ending at index ."

It makes sense to me how to accomplish this using recursive backtracking. However, I'd like my implementation of the search to use Thompson's multi-state approach. Is this feasible?

  • $\begingroup$ Isn't the grep utility already doing that ? $\endgroup$ – m.raynal Aug 28 at 20:07
  • $\begingroup$ You mean using the multi-state approach? $\endgroup$ – Daniel Walker Aug 28 at 20:29

It occurred to me after I made this post that I could store the states in a linked list format:

typedef struct stateRecord {
    struct stateRecord *next;
    size_t state;
    size_t startIdx;
    size_t endIdx;
} stateRecord;
| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.