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.

Comments:

James, Very interesting, but could you please make this available as an Eclipse update site as well? It would certainly encourage more people to play with javac (including myself).

Posted by Steve on January 08, 2007 at 05:56 AM PST #

I welcome the addition of shorter syntax for both variable declarations and maps. With regard to variable declarations I have suggested:

final fx = ... // final field or local
declare vx = ... // variable, none final, field or local

Which are equivalent to your suggestions of:

fx ::= ...
vx := ...

The reason for proposing the use of keywords is:

  1. Java syntax is characterised by un-abbreviated keywords instead of symbols, e.g. extends instead of :
  2. You would still need the keyword final (in the context of a variable declaration) for method argument declarations

Posted by Howard Lovatt on January 08, 2007 at 10:26 AM PST #

I'm not able to find the Javac project tool in the Netbeans 5.5 Update Center.

Posted by Rael on January 09, 2007 at 12:12 AM PST #

for some reason my (very insightful, appropriate and enlightening) comment was "marked as spam and will not be displayed". Was it because of all the (allowed) HTML formatting? It was there just to make my post more readable...

Posted by barspi on January 09, 2007 at 12:54 AM PST #

James, you say that you never have been happy with the debate about languages features. I totaly agree with you. But with the release of Java under open source these kind of debates will be come more often. This is the top reason I would hoped Java would stayed non open source.

Sun should stay in control on the language feature, but others may vote for there favorite language feature.

Giving everyone control over the languages features is a bad idea and may lead to the end of the langue.

Welcome to the dark side of open source.

Posted by Evert Tigchelaar jr on January 09, 2007 at 03:06 AM PST #

I've also been thinking that maybe once everything gets open sourced, it might be a good time to close down on the open process. The two don't _need_ to go together. And not that the process should be closed completely. Just that Sun should make sure it's clear that the community at large doesn't get to decide everything. Then we don't get our feelings hurt too much when things aren't _exactly_ what we want. I'm happy with fully open source license and a (partially) closed process, like the JCP for big issues with Sun deciding a lot of the little things on its own.

Posted by Tom Palmer on January 09, 2007 at 04:19 AM PST #

"...place where people could throw language features, no matter how absurd... With all due respect, I can't help but believe that something similar is already happening to Java through the BGGA closures proposal. Its a case of using a sledgehammer to drive home a small nail. At a time when Java newbies are still struggling to come to terms with (apparently) arcane rules of generics, the BGGA proposal seems to further complicate the type system. On the other hand, one gets to see no mention of the simpler CICE proposal on any of the "powerful" Java forums. I hope the JCP doesn't go merely by reputation and chooses the proposal that will serve the language well for the next decade atleast (without complicating it and bringing it down to its knees).

Posted by Bharath R on January 09, 2007 at 03:51 PM PST #

I had no idea you wrote Emacs! Even though it doesn't matter at all what I think - it somehow elevates your level of cool geek points. Nice work. :)

Posted by Jesse Kuhnert on January 10, 2007 at 03:06 AM PST #

ggffghtryty

Posted by guest on January 10, 2007 at 12:19 PM PST #

The problem with Fortran is not parsing but lexing. How did you handle that?

Posted by Frank Wilhoit on January 11, 2007 at 04:28 AM PST #

Bharath R: Mr. Gosling wrote \*an\* Emacs, but current GNU Emacs and XEmacs are not part of that line of descent.

Posted by John Cowan on January 13, 2007 at 12:22 AM PST #

javac with Netbeans is definitely very useful and i just wonder on the growth of NetBeans community over the last year. As Steve pointed out shorter syntax will be a big fun to play around. Dongan, www.brainjava.com

Posted by Dongan on January 13, 2007 at 11:01 AM PST #

Post a Comment:
Comments are closed for this entry.
About

jag

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today