An LOLCODE interpreter using JJTree

29 Sep 2007

Here's something that's lingered in my blog TODO queue for far too long. Brian Egge, formerly of ThoughtWorks and now of Macquarie Bank Limited, wrote an LOLCODE interpreter with JavaCC and JJTree. Behold:

$ bin/lol.sh test/samples/hello_world.LOL 
HAI WORLD!

I salute his efforts in this crucial field and humbly submit a small patch:

Index: src/com/lolcode/parser/LolCode.jjt
===================================================================
--- src/com/lolcode/parser/LolCode.jjt  (revision 20)
+++ src/com/lolcode/parser/LolCode.jjt  (working copy)
@@ -141,7 +141,7 @@
 {}
 {
   <IM> <IN> <YR> <LOOP> <EOL>
-  ( LOOKAHEAD(2147483647) Statement() )+
+  ( LOOKAHEAD(Statement()) Statement() )+
   <IM> <OUTTA> <YR> <LOOP> <EOL>
 }
 
@@ -157,7 +157,7 @@
 {}
 {
   IncrFunction()
-|  LOOKAHEAD(2147483647) BreakFunction()
+|  LOOKAHEAD(BreakFunction()) BreakFunction()
 |  <IZ> BoolExpression() <O_RLY> <QUESTION> <EOL> then() ( Else() )? <KTHX> <EOL>
 | <OPEN> <IDENT> <QUOTED_STRING>
 }
@@ -245,4 +245,4 @@
    return t.image.substring(1, t.image.length() - 1);
  }
 }

I'm just happy to be able to contribute anything to this work. Go Brian!