So today’s question is : can ChatGPT write a parser from an Instaparse grammar?
Why, yes! Yes it can!
See the full dialogue here.
This is the backstory.
Goldenpond is currently a little language for describing chord progressions; and some extra functions for organising the notes of these chords in time. Into arpeggios, rhythmic basslines and the like.
But I’m now working on a second little language for expressing these complex rhythmic and timing patterns, in as brief but elegant and composable way as possible. As this second little language is getting more complicated, it will also need a proper parser.
Now something I like very much in the Clojure language ecosystem is the Instaparse library. Together with a great web-tool called Instaparse Live. With that tool it’s easy to test and prototype a parser simply by writing the grammar in a BNF-like dialect of EDN. For Clojure programs, this is a great way to implement embedded domain-specific little-languages.
However, I’m not writing Goldenpond in Clojure. (Which is sad, because it’s still my favourite language.) The reason is that Goldenpond needs to run in several different places and on multiple platforms. Some where Clojure isn’t viable. So instead, I’ve chosen to work with Haxe which has the virtue that it transpiles to multiple languages and environments. Including the four that most interest me at the moment : Python, C++, Javascript and Java.
So I needed to write a parser for this second, rhythm language. Instaparse Live is a great place to prototype and develop that. But I need the final code in Haxe. Can ChatGPT oblige?
As you can see from the transcript, there were a few bumps along the way. Clearly GPT sometimes doesn’t remember exactly how Haxe works and uses an idiomatic style that probably cross-bled from Java. Note how, for example, it tries to use inner classes. Something that Haxe doesn’t have.
It makes some other mistakes too.
However, it didn’t take long to iron them out. And I am, once again, super impressed. By just how clever GPT is. And how empowering it is.