Summary
A new string manipulation language has been made, using only the characters $+#-!*|@>
! Your task is to implement an interpreter for it in as few bytes as possible.
Input
A string, which is a single line of this language. This can be taken in any reasonable way (stdin, function parameter, command line argument etc.), or as a predefined variable. If the program asks for user input, accept all user input it asks for from stdin and nothing more, see below. You may assume it is a valid program.
Output
Whatever the language would output, specifications below. You must output a string, in any reasonable way (stdout, function output, etc.), or a variable value. When the language outputs explicitly, this must go to stdout. Standard loopholes are banned.
Language Specifications
Processing and Syntax
The language has a very simple form of processing as it does only string manipulation: it starts with an empty string (""
), and changes it with each term. A term is made up of one or two parts: a function (below) followed by possibly a parameter(below), which edits its behaviour. Terms are separated by pipes (|
). You may assume it will not be an empty program, and no term will be empty. You should output the value at the end of the program.
Functions
The language has just 6 functions, as shown below. Each function either accepts one or zero parameters.
+
concatenate strings (takes one string parameter, concatenates it to the current value)!
reverse the character order of the current value (no parameter)*
repeat the string (takes one integer parameter, repeats the current value that many times)-
removes all occurrences of a value (takes one string parameter, removes all occurrences of it from the current value)$
[pseudo-]randomly shuffles the current value (no parameter)<
output the current value tostdout
(no parameters)
Values
These are the values that may be passed to functions, represented by regex that would match them:
@[^|]*
a string literal, including any character other than pipes. It may be empty.#[0-9]+
an integer literal>
the next line ofstdin
. If used with*
, convert to integer.
Test Cases
╔════════════════════════╤═════════════╤══════════════╗
║code │input │output ║
╟────────────────────────┼─────────────┼──────────────╢
║+>|!|+@hello|*> │13 │31hello31hello║
║ │2 │ ║
╟────────────────────────┼─────────────┼──────────────╢
║+>|+@abcdefg|$ │hello │hcloeebafdlg ║
╟────────────────────────┼─────────────┼──────────────╢
║+@how areyou|-@o|-> │w │h areyu ║
╟────────────────────────┼─────────────┼──────────────╢
║+@out|<|*#3 │ │out ║
║ │ │outoutout ║
╟────────────────────────┼─────────────┼──────────────╢
║+> │what ever 345│what ever 345 ║
╟────────────────────────┼─────────────┼──────────────╢
║+@$pe<i@l|<|-@$pe<i@l|+>│A|$o $pe<!@| │$pe<i@l ║
║ │ │A|$o $pe<!@| ║
╟────────────────────────┼─────────────┼──────────────╢
║<|+>|!|< │input text | ║
║ │ │txet tupni ║
║ │ │txet tupni ║
╟────────────────────────┼─────────────┼──────────────╢
║+@># │ |># ║
╚════════════════════════╧═════════════╧══════════════╝
Note that test case 2 is random, so any permutation of the characters in it is valid. Also, the outputs in the table are seperated by newlines, but your program doesn't have to do the same. The last value in each case the the final output.
Example (Un-golfed) python interpreter
Try it online! IMO better if you run it through IDLE or whatever you use. (I golfed it down to 424 bytes after, but I'm sure you lot can do better).
<
is encountered. Is this mandatory? \$\endgroup\$+@>#
? I used#
aswell. \$\endgroup\$