Thursday, March 13, 2008

Today's riddle: why does CUP emit the generated parser as TWO classes?

OK, so when you use CUP to generate a parser, it emits two classes: a parser class, and an action class (which contains the code generated for the semantic actions associated with the productions of your grammar). These are totally separate classes.

Today's riddle is this:
Why is the code for the semantic actions generated in a separate class?
Here are some possible answers:
  1. Your guess is as good as mine.
  2. Look in the user manual to find out --- oh wait, the user manual doesn't explain this.
  3. To ensure that you must violate encapsulation in order to allow semantic actions to refer to internal parser operations?
My complaint is that if you want add additional fields--for example, a symbol table object---the semantic actions can't directly refer to it!

The action code can refer to the parser via a field called parser, but that's only useful for calling public methods on the parser object. But that means that any internal parser state/operations that the semantic actions want to access must be exposed as public, violating encapsulation.


Wednesday, March 12, 2008

GUI Builders for Eclipse

The time has come to talk about GUIs in the Software Engineering course I'm teaching currently, which led me to revisit using a GUI builder in Eclipse. (I will not hand-code a Swing GUI. I just won't.)

Previously I've used the Eclipse Visual Editor plugin, which, while not perfect, generally gets the job done. To my dismay, the current release of the VE does not work with the current stable release of Eclipse, and there has not been an official release of the VE since June 2006. (So sadly neglected / and often ignored / a far second to Belgium / when going abroad / Finland, Finland, Finland :-) I hope this project gets reinvigorated at some point, but I wasn't going to sit on my hands waiting for that to happen.

A quick google search turned up Jigloo, an Eclipse-based GUI builder which, while not free software, is gratis for non-commercial use. From my 10 minutes or so of using it, it appears to be very nice, quite a bit more polished than VE. We'll see how it goes, but I'm cautiously optimistic it will do what I need it to do.