David's Compilers Survival Guide
Taking CSE 131A at UCSD means two things:
- Your life will be consumed by Java.
- 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.
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.
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:
- /[Your Project Name Goes Here. I recommend picking something cool as a codename]
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.
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.
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.