# [PowerShell] 7, <sup><strike>133 ... 101</strike></sup> 100 bytes -5 bytes thanks to Wasif! Then +1 byte to fix an issue with `--` always being read as the decrement operator, regardless of context.<br> -2 bytes thanks to mazzy! Takes input as an array of directives in the form `@('command','operation',number)`; the output is a TIO-Compatible PowerShell program. <!-- language-all: lang-powershell --> 'switch("$args"|% T*y){' $args|%{$1,$2,$3=$_ "$1{`$a=" $2[1]?"""`$a*""*$3+1|iex}":"`$a$2 $3}"} '}$a' Link is to a 116-byte TIO-Friendly (PowerShell 6 and below) version of the code. [Try it online!][TIO-Friendly-Generator] ### Explanation <!-- language-all: lang-powershell --> 'switch("$args"|% T*y){' # The first part of the interpreter switches # on the input program's characters. Switching # on an array in powershell processes the # switch statement for each element. $args|%{$1,$2,$3=$_ # For each array in the input array, set $1, # $2, $3 to the first, second, and third # element, respectively. "$1{`$a=" # output the case for the letter of the command # start the case with setting the accumulator # equal to whatever else is in this case $2[1] # If the second character of the command exists # In other words, the command is '**' ?"""`$a*""*$3+1|iex}" # Make the body of the case a special way to # calculate powers in PowerShell which is # shorter than [Math]::Pow - effectively # builds a string representation of the # calculation, then evaluates that string. :"`$a$2$3}"} # If the command isn't '**', we just make the # command '{accumulator}{command}{number}' # for example: '$a/3', making the whole case # '{$a=$a/3}' '}$a' # Close the switch block, output the accumulator ### Output Outputs a very ugly interpreter; for the example input provided in the challenge, the interpreter looks like this: ``` switch("$args"|% T*y){ a{$a= "$a*"*3+1|iex} b{$a= $a*2} c{$a= $a+15} d{$a= $a=0} e{$a= $a/8} }$a ``` And, of course, [Try The Output Interpreter!][TIO-Interpreter] [PowerShell]: https://github.com/TryItOnline/TioSetup/wiki/Powershell [TIO-Friendly-Generator]: https://tio.run/##HctBCsIwEIXhfU5RhinTpBFtguCm4CHca63RFgpqI1RJc/aYZPEW3w/v9VzMbAczTSGQXcZPP1SA3fywsJbFSfy4I5a9lg4biUqibvHMABt3wa4FNt4rVBvzJiGIOwCIWQAI1HWzjubrwZvJGpc6qgJ1DJ6Bj4QQwrGijmQ6S82TrkkkVUYfUZNs9lm3qJbkLsNEbOMOxP8 "PowerShell – Try It Online" [TIO-Interpreter]: https://tio.run/##K8gvTy0qzkjNyfn/v7g8syQ5Q0NJJbEovVipRlUhRKtSs5orsVol0ZYLKKqlpGWsbViTmVpRy5UEFgSKKRjVciVDOdoKhqa1XClQnq2CQS1XKpSjr2BRy1Wrkvj//3/15MSklOSkpFR1AA "PowerShell – Try It Online"