My Unstructured Scripting Language

Over the past few weeks, I've spent some time updating my little BASIC dialect, which I called Musl (or MUSL, depending on my mood).

The name can mean either My Unstructured Scripting Language or Marginally Useful Scripting Language, also depending on my mood. Musl's home official page is at http://wstoop.co.za/?musl and I have now set up a repository on Github at http://github.com/wernsey/musl.

If I remember correctly, Musl started out in 2009 when after a couple of beers at a work function I joked that I wanted to create a scripting language that had only IFs and GOTOs. The joke started because some of my earliest memories of programming come from writing simple programs in GW-Basic when I was in primary school.

The goal was to see exactly how little I could get away with. The very first version had a recursive descent parser that created an abstract syntax tree and interpreted it from there. Later, I realised (after seeing this BASIC interpreter's source code) that if you scan the source code for the labels then you don't even need the AST.

The latest version of Musl scans the input text for labels before interpreting it. It interprets the code with a pointer that runs through the input text and when it encounters a jump (GOTO, GOSUB or RETURN) the pointer is adjusted accordingly. Musl did not have a GOSUB and RETURN originally, but they were easy to add (GOSUB pushes the current value of the pointer to a stack before jumping, and RETURN then pops that value off the stack again).

I've been working on a Retro-style game engine lately, for which I thought that having a BASIC interpreter available would be an appropriate homage to the computers and the games we played on them while growing up, hence my renewed interest in Musl.

From the start I've written the code in such a way that the interpreter can be embedded within a larger project. It was intended to be a joke: Write something awesome in it, and then take pictures of the horror on my friends' faces when I showed them the source code.

Don't worry, though, I plan to give the engine a proper scripting language, probably Lua, and Musl will only be there for the nostalgia.