-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NFA -> DFA transformation + optimizations in this domain #8
Comments
That's a really interesting article - thanks. |
Just FYI - I've been exploring a multi-state NFA algorithm, which is conceptually similar to a DFA (it is in some senses an emulated DFA): https://github.com/ColinEberhardt/assemblyscript-regex/tree/multi-state-NFA However, it doesn't appear to be any faster in my benchmark tests! |
As I understand NFA -> DFA not helps in some scenarios. |
I believe the principal advantage is that DFAs do not result in back-tracking. However, many simple regex's do not result in any significant backtracking. This is why I'm keen to add some more complex expressions to the benchmark test! |
Also It seems this part could be a more effecient: function addNextState(
state: State,
nextStates: State[],
visited: State[]
): void {
if (state.epsilonTransitions.length > 0) {
for (let i = 0; i < state.epsilonTransitions.length; i++) {
const st = state.epsilonTransitions[i];
if (!visited.includes(st)) {
visited.push(st);
addNextState(st, nextStates, visited);
}
}
} else {
nextStates.push(state);
}
} with avoiding recursion and use stack / queue instead. Also |
Great article about this:
https://jasonhpriestley.com/regex-dfa
The text was updated successfully, but these errors were encountered: