A Regular Expression Matcher (2007)
cs.princeton.edu
A Regular Expression Matcher (2007)
1–10 of 36 posts
Re: A Regular Expression Matcher (2007)
#2Re: A Regular Expression Matcher (2007)
#3Re: A Regular Expression Matcher (2007)
#4The code lives up to its goal of being a good example of programming. As Kernighan says, it shows the value of handling special cases early and of recursion. (It's also a good example of how pointer-arithmetic and nul-terminated strings should be used, but the less said about that, the better).
Students are likely to not notice the tail recursion, so converting this to an iterative version is probably a nice exercise.
But notice that explaining regexps is a non-goal of this example. There is an underlying state-machine here (encoded in a combination of the instruction pointer and the `text` variable), but it is not very obvious. For that, Russ Cox' articles are the go-to.
Re: A Regular Expression Matcher (2007)
#5 if(x) {
do_y();}
2 characters, no vertical space difference. Unbraced blocks only feature is they introduce bugs - they have no legitimate use. But man do you feel like a tough, macho-man "I'm such a hard man I leave my blocks un-braced."Is there a list of languages that repeated this C idiocy (an optimization of syntax for the parser rather than the programmers?) I sure hope those languages that would like to replace C, ie D, go, Rust etc. Haven't repeated it this far into the 21st century.
Re: A Regular Expression Matcher (2007)
#6I'm impressed. The code lives up to its goal of being a good example of programming. As Kernighan says, it shows the value of handling special cases early and of recursion. (It's also a good example of how pointer-arithmetic and nul-terminated strings should be used, but the less said about that, the better). Students are likely to not notice the tail recursion, so converting this to an iterative version is probably…
Why the less said the better?
I'm always disappointed when people say C is bad at string manipulation. The "character at a time, no allocations needed, stop when you hit the end" style demonstrated here and elsewhere have always resonated deeply with me.
Re: A Regular Expression Matcher (2007)
#7Re: A Regular Expression Matcher (2007)
#8I found I didn't hate, loathe and detest unbraced blocks any less when it's Rob Pike code if(x) { do_y();} 2 characters, no vertical space difference. Unbraced blocks only feature is they introduce bugs - they have no legitimate use. But man do you feel like a tough, macho- man "I'm such a hard man I leave my blocks un-braced." Is there a list of languages that repeated this C idiocy (an optimization of syntax for th…
if a == b {
stuff();
}Re: A Regular Expression Matcher (2007)
#9I wasn't sure I wanted to deal with computers on a day to day basis when I took the course. The lecture blew my mind, and I started looking for programming jobs the next day.
[1] COS333. Memories... man, I'm getting old.
Re: A Regular Expression Matcher (2007)
#10I appreciate that he acknowledges me at the end. Thanks Rob!
exegesis is a nice word to have in one's vocabulary. brian is a good exegesist (or is that exegesisticist?)