ANTLRWorks and OpenJDK Compiler Grammar

Now that my qualifying exam is behind me, I’ve got more time to focus on other things. I have to admit that the exam pretty much occupied all of my thoughts and hogged lots of time, to the degree that I didn’t prepare as well as I used to for my COMP 202 class. I think that has changed again now.

I’m also starting to look at the Java multi-stage programming project again, and I discovered that the OpenJDK people have added a Compiler Grammar project. This project is trying to replace the hand-coded parser for javac by a parser generated from an ANTLR grammar file. I haven’t fully checked how far this has progressed, but it is interesting. Modifying the grammar to allow annotations on statements and expressions should be easier than rewriting the interpreter by hand. It seems like there is a Java 5 grammar that integrates into javac, but of course there is no JSR 308 grammar, so I’d have to develop that first.

When I looked at ANTLR and the Compiler Grammar project, I also noticed an interesting IDE that has been built to make developing grammars easier: ANTLRWorks. It integrates a several checking tools and a debugger and looks tremendously helpful. For example, it can explain how a grammar is ambiguous. In my case, an annotation on a parenthetical expression could be parsed in two different ways, so I’ll have to be careful there.

ANTLR Ambiguous Path Visualization

ANTLR Ambiguous Path Visualization

On MacOS, I’m still struggling a bit to get the Compiler Grammar project and ANTLRWorks running. It seems like Compiler Grammar needs SoyLatte to work, and I have managed to build the Compiler Grammar javac from the command line, but when I try to run it inside ANTLRWorks, then it seems like it is using the default Apple Java version 1.6.0-dp, which doesn’t work. Maybe I’ll take a look at it on Windows first.

I also need to start thinking about the COMP 202 final exam, and about a lecture schedule and programming tasks for COMP 402 next semester.


About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in COMP202, DrJava, Pictures, Research, Review, xajavac. Bookmark the permalink.

Leave a Reply