The Bub interpreter

bub.mur is a Muriel program written to execute programs written in the Brainf*ck language. In fact it isn't an interpreter for Brainf*ck, but for a language called Bub (Brainf*ck Ugly Bodge). The idea is that it's trivial (although not trivial enough to conveniently write in Muriel) to translate from Brainf*ck to Bub, and therefore from Brainf*ck to Muriel via this interpreter. All of this goes to show, in a particularly long-winded way, that Muriel is Turing complete.

Essentially, Bub is Brainf*ck using GOTOs instead of 'while' loops. A Bub program consists of a string of digits, and these are split into blocks of 'w' digits (w=4 in the Hello World program). In most instructions, all but the last digit can be ignored - the last digit corresponds to a Brainf*ck instruction, with 012345678 corresponding to <>+-,.[] and 'end of program' respectively. In the case of [ and ], the preceding digits signify the instruction number to jump to (counting from 0) if the jump takes place - in other words, when translating from Brainf*ck to Bub, the location of the corresponding bracket is calculated in advance.

For example, the program [-] could be translated as

0036 9993 0017 9998

A quick overview of the interpreter: the first 7 lines set up what can be considered as global variables representing the state of the Bub program - the program, memory (which expands whenever the data pointer moves past the last location), program counter, input buffer, data pointer, ASCII table, and word length. After this, a single instruction is executed. Lines 9-30 read the next instruction and generate the Muriel code fragment which will be used to perform this instruction in the next pass. The last four lines are responsible for 'quining' the bulk of the program and starting the next pass of the Muriel program.

There's one major limitation of the interpreter as it stands - the present version of the Muriel language has no way to convert characters to their ASCII codes, so input to the Bub program must be given in the form of 3-digit decimal numbers rather than ASCII characters.