Long ago UNIX had compiler writing tools like yacc and lex. I wonder if they are useful for exercises like this.
replies(6):
FWIW, if I had to do this again today I would certainly go for hand-written recursive descent. lex/yacc charm you in but eventually prove to be much more difficult to tweak and reason about.