6
1
Input:
Any Brainfuck program. This includes brainfuck programs with comments such as +++COMMENT[>+++<-].
.
Output:
A program in one of the below languages that produces the same output as the Brainfuck program on all inputs. It should produce the same output exactly as the interepreter on this website There are no code-golf or performance restrictions on the output program; the outputted program doesn't need to be optimized in any way. In other words, the quality of the outputted program does not affect score, only the translation program. To clarify: you may write your answer in any language that is normally valid for answers on PCG. The restriction on output languages is only for the outputted program.
The outputted program only receives the same input that would be received by the Brainfuck program. The outputted program does not receive the Brainfuck program as input.
Valid Output Languages
- C#
- C++
- C
- Java 8
- Javascript ES6 (it is both okay to receive all of stdin in a single prompt, or multiple prompts per character)
- Perl
- Python 2.7
- Python 3.4.2
- Ruby
Fine Print
You may write a program or function which takes the Brainfuck program as a String argument or on STDIN or closest alternative, and which returns the output as a String or printing it to STDOUT (or closest alternative). You may optionally include a single trailing newline in the output.
Additionally, standard loopholes which are no longer funny are banned. You may not use external libraries or external data files, the code must be self contained.
This is code-golf, shortest program wins.
possible duplicate of Interpret Brainfuck
– mbomb007 – 10 years ago3It's not a dup, as a compiler is not an interpreter – edc65 – 10 years ago
It might not be a dup, but the question is whether there is a shorter solution than copy&pasting a golfed interpreter in one of the allowed languages; and copying the brainfuck to the output program. – blutorange – 10 years ago
3Can you clarify the behavior of the linked interpreter? What is the max number of memory cells? How is overflow of cell values handled? – nderscore – 10 years ago
2@nderscore The linked interpreter uses signed integers that wrap around from -128 to +127. However, the values are effectively cast to 2-byte unsigned ints before being output as characters; so -1 => chr(65535) (). Personally, I would prefer output in the form of 1-byte (ASCII) characters (in part because that's what my solution uses). The tape is circular, with 32768 cells. durron597, are these specs what you intended? – DLosc – 10 years ago
Any reason not to open this up to all output languages? – Adám – 6 years ago