David Stone's Blog

I'm open to suggestions for a subtitle here! (Really!)

David's Compilers Survival Guide

Taking CSE 131A at UCSD means two things:

  1. Your life will be consumed by Java.
  2. Your life will be consumed by XQuery.

It's non-negotiable. I didn't completely implement the interpreter last quarter. (The only thing I was missing was the order by interpretation for query comprehensions. It came down to the half hour before the assignment was due and I gave up on it, reverted to the last revision in Subversion, and turned in all my code.) But even without the orderby implementation, my code came out to around 10K+ lines. Divide that by the 9 weeks you get to write it all and you're talking over a thousand lines of code a week.

So, first things first. You do not want to do this class in vim. I don't care how hardcore you think you are, doing the entire class in vim will kill your productivity instantly.

Step 1: Get Eclipse

Unless you have the money to shell out for IntelliJ, Eclipse is the best IDE out there for Java. I'm always a fan of using the latest and greatest (aka, the bleeding edge) in the milestone builds. They're stable enough that the IDE won't crash on you while you're editing code and they allow some really cool features. Currently, 3.3M4 is the latest milestone. So go download that.

One of Eclipse's strong points is JUnit integration, which you'll definitely want to take advantage of in this class.

Step 2: Get Subclipse

I shouldn't have to explain that using version control is a necessary part of any software project. And while Eclipse comes with CVS support built in, I prefer using Subversion. So get Subclipse. You're going to want to set up your project and check it into your respository. Don't bother naming it A1, since you'll be editing the same project for the entire quarter. I set it up like so:

  • /cs131a
    • /a0
    • /[Your Project Name Goes Here. I recommend picking something cool as a codename]
      • Main.java
      • /lexer
        • Lexer.java
        • /tests

Eventually you're going to have a parser directory, a directory for your abstract syntax tree classes, etc. But for right now, all you'll need is your lexer directory.

Step 3: Get CUP/LEX

You'll be using JFlex and CUP for the lexer and parser in this course. You don't have to, of course, but it's recommended. And if you do, it'll be a lot easier if you have this plugin. It automatically re-runs JFlex and CUP on your .lex and .cup files when you save them, which in turn generates your Java files. It's slick. Use it.

Step 4: Get EclEmma

Emma is a free (and pretty darn good) code coverage tool for Java. Surprisingly, the Java code coverage tool space is dominated by commercial offerings, with a very sparse (and very new) set of open source tools cropping up to complement the rest of the open source stack (Eclipse, JUnit, Java itself now, etc.) The reason I chose Emma is that it had a very well integrated plugin for Eclipse: EclEmma. EclEmma is great because it integrates with your JUnit tests runs and provides coverage information for each line in the IDE and coverage statistics per-package, per-file, and per-class.

Step 5: Use JUnit to automate your testing

Eclipse has built-in JUnit integration. Use it. Kube provided us with XQuery files and their XML output from the reference program. This is nice, except for the fact that there's no convenient way to write JUnit code around it. What I ended up doing was writing a helper function for my JUnit classes that read in the XQuery file, ran the (Lexer|Parser|Interpreter) on it, and diffed the result against the reference result file that Kube gave us. I'll be uploading my test code to my ieng6 account sometime this weekend, when I have time to prep it for everybody. (I've also got a diff utility.)

If you use JUnit in conjunction with EclEmma, you'll get a nice green bar telling you that all your tests passed, and a nice green bar telling you how much of the code you wrote was actually covered. This will be especially useful for the lexer assignment.

Step 6: Start Early

I know everybody always says this. And nobody ever follows it. I started writing A1 (the lexer) about two days before it was due, same with A2 (the scanner). With A3 (the interpreter), I started a whole 8 days in advance. That's a grand total of 12 days. I probably had 100+ dollars worth of Starbucks/Pepsi/etc during that time, almost no sleep, and absolutely no free time. And I wrote nearly 11 thousand lines of code. Don't be stupid. Start early.

There you go. That's the advice I've got. If you've got any more questions about the class or about the tools and how I've got them set up, go ahead and e-mail me.

Enjoy.

Comments

Scott Perry said:

<3

Thanks, this will be indispensable really soon

# January 10, 2007 8:26 PM

jauricchio said:

So, first things first. You do not want to do this class in vim. I don't care how hardcore you think you are, doing the entire class in vim will kill your productivity instantly.

I take that as a goddamn <b>challenge</b>.

# January 10, 2007 10:53 PM

Mooneer Salem said:

Code coverage? JUnit? That's for losers. :P

# January 12, 2007 5:13 PM

Nish said:

You should think of writing "David Stone's effective guide to doing college projects" :-)

# January 15, 2007 2:28 PM

Nish said:

You should think of writing "David Stone's effective guide to doing college projects" :-)

# January 15, 2007 2:28 PM

weblogs.asp.net said:

David s compilers survival guide.. Retweeted it :)

# April 18, 2011 11:20 AM

weblogs.asp.net said:

David s compilers survival guide.. Very nice :)

# May 5, 2011 11:02 AM

weblogs.asp.net said:

David s compilers survival guide.. Keen :)

# June 18, 2011 10:13 PM