You could use context-sensitive compression, in which the encoding for a command depends on what comes before it. Also, you don't need a separate EXIT command, just use the ] command as a end of file marker. For example, + and - will not occur together in either order, < and > will not occur together in either order, a > must occur in the program first before any < occurs, a [ will not occur at the beginning of the program, etc. --Zzo38 21:40, 15 December 2007 (UTC)
Calculation of left context probilities
The overall probabilities I found made the Huffman algorithm give an encoding that was substantially equivalent to the unary prefix code. That is ...
The probabilities for the next character followed the same pattern with the exception that for the '>', '<', '+', '-' codes there was an over 95% probability that the next character would be identical and a very small probability, though not zero) that it would be the opposite. The other codes appear to follow the global probabilities.
|> or start of file||>||+||-||]||[||.||,||<|
|[ ] . ,||>||<||+||-||]||[||.||,|
If wanted the 'debug' and 'termination' codes can be added in the obvious place, though I suspect using '11111111' as an 'escape code' with the eight bits in ASCII would be better. (And use 11111111 + 0 to 7 bits padding + EOF as an alternate termination)
Overall, however, it appears that simple run length encoding gives better compression performance.
Rdebath (talk) 11:20, 28 September 2013 (UTC)
Erikkonstas (talk) 13:23, 19 July 2016 (UTC)
- https://github.com/rdebath/Brainfuck/blob/master/extras/ook.l Now does Spoon and several others. Rdebath (talk) 08:10, 20 July 2016 (UTC)