3 ms·
a 231-byte Brainfuck-to-C compiler* It's still an impressive feat, and very informative on the assembly details - but doesn't feel as incredible as the headlin
by xg15 5y ago
a 231-byte Brainfuck-to-C compiler*
It's still an impressive feat, and very informative on the assembly details - but doesn't feel as incredible as the headline makes believe as the core logic seems to be a string search-and-replace of the strings in the "reviewing brainfuck" table.
Seems to me, you could write the next brainfuck compiler in sed.
- zelon88 5y agoIt seems more like a parser than a compiler. It doesn't write a binary, it just translates brainfuck to C source code. In the OPs defense, they did say "by abusing everything."
- barosl 5y agoA compiler doesn't have to emit machine code. It just needs to translate one language into another, which the author's program does. Also, a parser implies having an internal, structured representation. As the C language is neither internal nor structured, I'd say the program is more likely a compiler.
- recursive 5y agoI blame the rise of the word "transpiler" for making people think that compilation is some more magic/narrow/special thing.
- whatshisface 5y agoThere is a practical, empirical distinction between compilers and transpilers. Most compilers in practice have backends full of deep and well-explored techniques specific to machine code like register allocation, window optimizations, and other stuff like that. Most transpilers you see out in the wild share more in common with compiler frontends in the techniques and the theory they apply.
- mywittyname 5y agoThe term transpiler arose when there was a need to denote a special kind of compiler whose target is another language or version of the same language.
- notme77 5y agoWell then, I can write a tiny C compiler in bash...
- DonHopkins 5y agoShouldn't the point of doing something as practically useless as compiling brainfuck be to do it in the most difficult way possible? I'm more impressed by a brainfuck compiler written in brainfuck. https://news.ycombinator.com/item?id=697501 https://news.ycombinator.com/item?id=697501 https://github.com/matslina/awib https://github.com/matslina/awib Awib is a brainfuck compiler entirely written in brainfuck. Awib implements several optimization strategies and its compiled output outperforms that of many other brainfuck compilers Awib is itself a 4-language polyglot and can be run/compiled as brainfuck, Tcl, C and bash Awib has 6 separate backends and is capable of compiling brainfuck source code to Linux executables (i386) and five programming languages: C, Tcl, Go, Ruby and Java
- user-the-name 5y agoThe original point of Brainfuck was actually exactly to make the smallest possible compiler for a Turing-complete language. The original was 240 bytes, and created an executable directly.
- blacksqr 5y agoBrainfuck interpreter written in Tcl: https://wiki.tcl-lang.org/page/Brainfuck https://wiki.tcl-lang.org/page/Brainfuck Brainfuck-to-Tcl transpiler: https://wiki.tcl-lang.org/page/Brainfuck-to-Tcl+transpiler https://wiki.tcl-lang.org/page/Brainfuck-to-Tcl+transpiler