At university the by far coolest and most fun course was compiler construction. We had to write something which would compile a small subset of Java (Javalette) into the Java Virtual Machine instruction set.
I wrote my compiler in Haskell because it seemed that it'd be much less hassle compared to do it in a object oriented or procedual language.
It ain't pretty but it's honest work: https://github.com/jeena/CC/blob/master/Compiler.hs