Recursive Descent Child-Watching

Yes, this is a true story.

Recently (if you consider the course of a year as “recent”) I have been interested in parsers, particularly the kinds that are used for creating programming languages, which include as a subset, expression parsing. Such an expression might be: (1 + 2) * 3 – (4 / 5). This is actually a bit more tricky than you might initially think, at least to get a computer to solve the expression. A “recursive descent parser” is one of the common solutions, and is relatively simple and elegant in design.

I also have three kids, two of them under the age of six (4 and 5.5 years at the time of writing) so I only get quiet programming time after about 10pm. I’m also a late night kind of person, so I’m usually up till 2am hacking away at something or another. My wife on the other hand is more of an early riser and she sometimes has 7:30am meetings (yuck!) for work. The other day was one of those days.

Generally what happens on the “early meeting” days is that my wife will take the teenager to high school, then she’ll go to her meeting and return about 9am to take the kids to daycare (I have the luxury of being able to work from home quite a bit). I generally try to get up when the kids do, which is usually between 8am and 9am depending on how late *I* happened to stay up. It works like this, if I stay up late, the 4 and 5 year old always seem to wake up by 8am. If I happen to get to bed before midnight, they will sleep in till 9am. Explain that to me…

So, my wife has this “early meeting day” and I try to get up… I can’t do it. My eyelids will just not open. The 4 and 5 year old are happily sleeping in our bed (they generally join us sometime between 4am and 7am), and the clock says 8am. “Please…” I think, let them sleep till 9am. “Oh no!” I thought, but last night I was up till 2am, so that means they will certainly start waking up. “What can I do?” I thought. In that frenzy of desperation you have when you are only half awake and trying to rationalize to yourself how you can stay in bed just a little longer, it came to me in a microsecond!

I had been up till 2am hacking out my recursive descent expression parser, and in my moment of triumph to get just a little more sleep, my conclusion was this: I would simply use a recursive descent parser to watch the 4 year old, so if he tried to get out of bed he would simply “throw an error” and I would wake up. Problem solved. Back to sleep. 🙂

Eventually an error was thrown, but it was my wife who had come home to find the 4 year old running around the house yelling “hee yaw!” with his hands over his head and a ballpoint pen clenched in each fist. I was, needless to say, still in bed content that there were no problems with my parser. “He can’t possibly have been out of bed…” I exclaimed, “He would have thrown an error!”… It was no good, I could tell by the laser beams coming out of my wife’s eyes that she was not grokking my explanation. Now how do you debug your way out of that one??

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">