Compiler fun

There's lots of fun to be had playing around with javac. I've never been real happy with debates about language features, I'd much rather implement them and try them out. For example, over christmas, Rémi Forax did an implementation of the ":=" declaration syntax, along with some other type inferencing touches. [I used to give myself an annual christmas present: I'd do a "Christmas hack" that was just for fun... That ended when children entered the picture. My Christmas hack was fun, but children are better]

For years I've wanted to set up a "Kitchen Sink Language" website for experimentation. A place where people could throw language features, no matter how absurd, just so that folks could play around. Now that javac has been open-sourced, it's easy. Peter von der Ahé beat me to it and built the site, but he hasn't quite got it ready yet.

Playing with javac is particularly easy since it got repackaged as a NetBeans extension. It's an odd but slick way to make it easily available: when running NetBeans 5.5, go to the update center. You'll find a javac project tool... Download it and create a javac project. It gets pre-populated with all the sources of javac. Lots of fun.

Even if you don't want to create a new language extension, installing the javac sources is interesting if you like studying compilers. It's a particularly nicely written one. No, I didn't write it: I wrote the original java compiler, which was a C program. It has thankfully been dead for years.

If you're into extreme sillyness, you can rewack the parser completely so that it will compile other languages. Several years ago I actually wrote a Fortran parser on top of javac - it was good enough to compile LINPACK, but not much else. I did eventually come to my senses and throw it away.

Another thing you can use javac for is dropping code into it that studies the parse tree. I like to do that when analysing language features: come up with a tree walker that looks for things that could be rewritten to use a proposed new feature. Rather than using javac, you can play with Jackpot in NetBeans to get the same capabilities (Jackpot is really just a UI for the AST). It's pretty depressing how few new language features improve more that a thin sliver of code. One of the reasons I like ":=" and operator overloading for [] to map to container classes is that they simplify visual clutter all over the place.

January 8, 2007