
Today I gave a small talk about some of the most interesting work that we were able to do over the years at my current job, or at least a subset of it.
The best times were when real computer science principles were put into practice. The pinnacle of that, in my mind, was the invention of a small
expression language, replete with constants, variables, mathematical operators, comparators, string literals, boolean operators, arbitrary nesting of parentheses, and functions with an arbitrary number of arguments (each argument potentially being any arbitrary sub-expression).
Hand-rolling a
parser for such a language would be a perverse exercise, but the simple application of some time-tested tools made the problem approachable and, in retrospect, even trivial.
There are two main tools that we used.
The first was a conceptual tool:
context-free grammars. These were first invented by
linguists to model the structure of
natural languages, and adopted by computer scientists in the early days of experimenting with programming languages. You can think of these as
rigorous mathematical formalisms of the same idea behind the grammar rules you learned in junior high school.
(Do they even teach
diagramming anymore?)
The second tool was a
parser-generator. These are an incredible invention: they read-in the aforementioned grammar,
automagically generate a
provably-valid parser for the language, and provide a way for you to subsequently define the
semantics of your language.
The particular parser-generator that we used was
SableCC, which had a nice, novel way of allowing one to define the semantics of the language they wished to invent: while most other parser-generators expected us to modify generated
source code, SableCC merely generated an
interface that allowed us to implement a vistor, in the sense of the
visitor design pattern.
Slick.
Inventing languages in this manner used to be
de rigueur among computer programmers who had become somewhat advanced in their technique. Today most need for small custom languages (configuration languages, typically) is satisfied by
XML, which is much easier to wrap one's mind around. This renders the work facile, but with the tradeoff of rendering the resulting language inelegant -- and rendering the programmer flaccid.
Mind you I'm not saying this as someone who considers himself an expert in the subject, but as someone who felt the rush of sudden
experience points just from having gone through the exercise once.
One day
Vint Cerf came to speak to us at work, and I got the opportunity to be among a few who attended a small breakfast with him. Mostly I just listened, drinking in as much of his luminosity as I could. Eventually, however, his eyes fell upon me and he asked me to describe what I did.
I told him. He sat back, smiled, and said that he was very happy to hear that language invention was still alive and well in the corporate world.
I feel very fortunate to have had the opportunity to practice real computer science on the job -- it's so much more rewarding than charting the path of one's career by popular shrinkwrap, entrenched brands, or skyrocketing buzzwords.
It's the road less travelled, but the view is lovely.