15-150: Principles of Functional Programming

Lecture 15: Regular Expressions continued (Proof and Combinators)

Today we discussed the proof of correctness for our regular expression matcher from the previous lecture. We broke the proof into three parts: termination, soundness, and completeness. Last time we had sketched the termination case, seeing that the proof failed for Star in our initial implementation. We used that failure to fix the code. This time we focused on soundness and completeness, and wrote out the part of the proof for Plus. Please look at the lecture notes from last time for the full proof. We only did a small part of the proof in lecture.

Next, we discussed rewriting our regular expression matcher using combinators. Combinators help us separate the processing of the regular expression from the actual character matching and continuation-based control flow. This separation facilitates staging: The regular expression pattern matching is in one stage, the character and continuation functions are in another. One can thus produce a matcher for a regular expression without ever seeing any input or continuations.

For a review of staging see Lecture 11.

For the unstaged regular expression matcher see Lecture 14.

Sample Code

See also Section 3 (on Kleene Algebra Homomorphisms) of these notes from last time.