There already is a Brainfuck interpreter question, but it is from 2011 and not up to date with current site standards and vague in places. I have proposed reposting this in chat, and it was well-received. Here goes.
Objective
Given the Brainfuck code and the program's input as input, run the Brainfuck code. As there are various variants of Brainfuck, here is the one I will use for the challenge:
- There are least 128 cells.
- Cell values are positive integers, having a maximum value of at least 128.
- Going into negative cells in undefined.
- Going into negative numbers is undefined.
- Going above the maximum cell value is undefined.
- EOF is 0
You may assume that the code will conform to the above constraints and that brackets will be balanced. You may also assume that all input code will be nothing but <>,.+-[]
.
Testcases
"+[-->-[>>+>-----<<]<--<---]>-.>>>+.>>..+++[.>]<<<<.+++.------.<<-.>>>>+." -> "Hello, World!"
",[.,]", "abc" -> "abc"
Scoring
As this is code-golf, shortest answer in bytes wins.