Brainf**k is the most famous esoteric programming language and is the inspiration for hundreds of other esoteric languages. In fact, there are quite a few languages that are so heavily based off of Brainf**k that the only difference is the characters used. Your challenge is to interpret one of these languages.
Brainf**k uses these commands:
> Move pointer to the right < Move pointer to the left + Increment the memory cell under the pointer - Decrement the memory cell under the pointer . Output the character signified by the cell at the pointer , Input a character and store it in the cell at the pointer [ Jump past the matching ] if the cell under the pointer is 0 ] Jump back to the matching [ if the cell under the pointer is nonzero
Trivial Brainf**k Substitution
Brainf**k | Ook | Command ----------------------------------------------------- > | Ook. Ook? | Move the pointer to the right < | Ook? Ook. | Move the pointer to the left + | Ook. Ook. | Increment the memory cell under the pointer - | Ook! Ook! | Decrement the memory cell under the pointer . | Ook! Ook. | Output the character signified by the cell at the pointer , | Ook. Ook! | Input a character and store it in the cell at the pointer [ | Ook! Ook? | Jump past the matching Ook? Ook! if the cell under the pointer is 0 ] | Ook? Ook! | Jump back to the matching Ook! Ook? if the cell under the pointer is nonzero
Ook is exactly like Brainf**k, except for the syntax.
TrivialBrainfuckSubstitution is a function defined as:
TrivialBrainfuckSubstitution(string1, string2, string3, string4, string5, string6, string7, string8)
Each string provided substitutes the corresponding Brainf**k character - so
string1 will be a substitution for
string2 will be a substitution for
<, so on and so forth.
For example, Ook! is equivalent to
TrivialBrainfuckSubstitution("Ook. Ook?", "Ook? Ook.", "Ook. Ook.", "Ook! Ook!", "Ook! Ook.", "Ook. Ook!", "Ook! Ook?", "Ook? Ook!").
Alphuck is equivalent to
TrivialBrainfuckSubstitution("a", "c", "e", "i", "j", "o", "p", "s").
To elaborate: Given eight strings representing the eight substitutions and a ninth string representing a program, interpret the program as a trivial Brainf** substitution.
TrivialBrainfuckSubstitutionmay take function arguments or command line arguments. These are the only ways it may take the first eight arguments.
TrivialBrainfuckSubstitutioncan take the ninth argument from standard input, a file, or a literal ninth argument.
TrivialBrainfuckSubstitutionmust be able to take any ASCII characters as substitutions. It does not have to handle Unicode, and you can assume there are no duplicate elements provided.
- Note that the actual function in your code need not be named
TrivialBrainfuckSubstitution. This is just the title of the function; the actual name in the code can be
x, or a lambda, or whatever you like.
- Your interpreter should not require any spaces between command substitutions. However, it should not break if they are present. To rephrase, it should ignore unrecognized commands, just like normal Brainf**k.
- You may assume that all substitutions are the same length. I.e. you may assume that
Bare never in the same substitution set.
Challenge-specific Brainf**k semantics
In your newly-created Brainf**k language:
- You do not need to be able to go left from the start of the tape. (You can choose to allow this.)
- The tape should have a minimum length of 30000. (If you want it can be longer or allocated dynamically.)
- The maximum value of the tape elements must be the maximum value for an integer in your (host) language.
- Input can be read from standard input or a file.
- An attempt to read
EOF(End Of File) should not cause any undefined behavior.
EOFmust simply be stored as would any other character read.
As with code-golf, the shortest submission wins. I won't ever accept an answer unless one is 50 bytes shorter than all others.
Also, as this challenge is somewhat more difficult than others (while certainly not the hardest), I kindly ask that you include an ungolfed version and explanation with your answer.