Parsing regular expressions with recursive descent
matt.might.net
matt.might.net
Parsing with derivatives can take advantage of the Pratt hack to go even faster.
My original automaton only has 8 states. ( http://www.jasq.org/uploads/1/0/5/6/10564637/977128_orig.png ) I guess that's the price you pay for cycles. ( Mine is a cyclic graph, but Rex produces a directed acyclic graph. Since they both must capture the same regex, one of them would be much larger than the other )
Hey, it's a yacc-compatible grammar.
First two articles:
* http://eli.thegreenplace.net/files/docs/forays/col1.html
* http://eli.thegreenplace.net/files/docs/forays/col2.html
The rest listed here: http://eli.thegreenplace.net/articles/
[1] http://swtch.com/~rsc/regexp/regexp1.html
See at the bottom of that articles for links to followups
Umm... I'm sure it's fascinating, but I've really got better things to do with my time, which is why I use RegExs in the first place :)
My point was that the original post seemed really judgmental in implying that building a RegEx engine ought to be done by everybody. Instead of "every programmer ought to have the experience", they could have said, "it can be valuable to have the experience".
But a blanket statement that every programmer should do X... is really annoying and shows a very narrow worldview. Programmers are diverse, and do lots of different things.
[1] The sentence that references this footnote uses the phenomenon it describes for emphasis.
[2] This is a similar, but distinct phenomenon of using a term, in this case speaker, with the implicit understanding that it can be generalized, in this case to "communicator". It shouldn't be confused with the situation described, but is also a useful pattern to understand for basic communication.
It will also help you understand why engines like re2[1] are absurdly faster than normal engines.
[1]: http://code.google.com/p/re2/
In short: it's a great learning exercise. Also, I suggest learning the basic theory behind it (Chomsky hierarchy and so on)--it's very fascinating.