Playing with Parsers

Lately, I’e been fascinated with the concept of parsing and developing my own simplistic programming language. When I have my work laptop with me, I’ve been playing with ANTLR 3, which has been fascinating. I’ve gotten my parser partially implemented so I can define new enumerated and collection types, declare variables, and even start declaring functions with parameters and a return type. Granted, I still have to add instructions to each function and make it so everything runs, but hey. Rome wasn’t built in a day, right?

The thing is, I really would like to do this on my home computer, which is a MacBook Pro. And while technically ANTLR was originally written for Java and will therefore work on MacOSX, I feel like that’s cheating. I’d much rather work with Objective-C and Cocoa (especially since I’m till trying to learn them.) Plus, I don’t know Java and the last thing I need to do is add to the list of programming languages I’m still trying to get better at (C# an Objective-C).

Granted, ANTLR 3 technically has an Objective-C runtime (allegedly, there’s even something written for Cocoa to parse ANTLR 3 grammars and create the parser and lexer classes), but it’s pretty darn old. It looks like the Objective-C development stalled about four years ago.

Plus, to be honest, I’d really like to use ANTLR 4, since the documentation for the older stuff seems to be partially missing. Plus I’m geeking out, which means I’d rather geek out with the latest and greatest. Naturally!

The thing is, the latest version doesn’t yet support targets (or have runtimes for them) other than Java right now. Well, that’s not true. I guess there’s a C# runtime and target, though I played with that a bit on my work computer and it seemed a bit undercooked. (Getting things to run was a nightmare.)

Naturally, I went looking for a Cocoa based alternative and found ParseKit. It seemed great, but I ran into a few problems.

  1. The instructions for including the framework into your own projects seems horribly buggy.
  2. Using the parser generator app that comes with the framework, I still haven’t been able to get my own basic grammars to work. I keep getting errors with not-entirely-helpful messages.
  3. There’s so little documentation for the framework, I might as well say there’s none.
  4. And once again, looking online suggests that this is a project that hasn’t been touched in a couple years.

How frustrating! So I finally figured out how to download the ANTLR 4 code and I’ve decided to try my hand at porting the whole darn thing to Objective-C myself. I’m not sure I’ll actually finish it. I mean, there’s a LOT of code. I figure I’ll start first by just porting what I need to recreate the tool that creates parser and lexer classes from grammars. If I can get through that, I’ll see about creating the necessary Objective-C runtime and the target to actually generate parser source in Objective-C.

This means that I often have a lot of windows open:

  1. Eclipse, so I can sort through the original ANTLR 4 (and ANTLR 3.5, since the former uses the latter in places) source.
  2. XCode, so I can work on my new Objective-C workspace.
  3. The XCode documentation window, so I can look up the Cocoa classes I’m still unfamiliar with and may need.
  4. Firefox so I can look up details about the Java code I don’t understand. (Sadly, this may mean I learn Java after all.)

And to think, this is what I often do for fun. Some days, I think my middle name should be “Masochist.”


One thought on “Playing with Parsers”

Leave a Reply