by yakubin · 4y ago · 0 comments
> This backtracking-based approach works, but it comes with a problem. The number of branches we need to test can exponentially increase with the size of the regex in certain situations, which means that testing all the branches would potentially take forever.
I think that's where it went wrong. And my comment is also subtly wrong in that it implicitly assumed this is right and proceeded from there.
The important part though is that simulating an NFA grows with the regex, while with DFA it doesn't, and you can also find it in Russ's article ("Caching the NFA to build a DFA").
The article's claim that this is what grep and AWK use is also contradicted by Russ. Claim:
> Incidentally, this is the approach used in grep and awk.
Russ:
> Awk, Tcl, GNU grep, and GNU awk build DFAs, either precomputing them or using the on-the-fly construction described in the next section.
[1]: Most sources claim that it's actually O(nm^2), where m is the number of states of NFA (which is linear to length of regex, so you can treat m as length of regex as well).