Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Brainfuck to C compiler

Name: Anonymous 2014-04-30 9:44


Brainfuck to C compiler
=======================

$ ls -l
42319 bf
2315 bf2c.bf
107 hello.bf
11452 mandel.bf
934 quine.bf
$ cat bf2c.bf
--[------->++<]>-.[->+++<]>.+++++.-----------.+++++++++.+++++++++.+[->+++<]>+
+.+.--[--->+<]>-.--[->++<]>.--[->++<]>-.+.++[->+++<]>++.+++++.++++++.[->+++++
<]>+++.+[--->+<]>+++.++[->+++<]>.>++++++++++.-[->++++<]>-.[->+++<]>.+++++.---
--------.+++++++++.+++++++++.+[->+++<]>++.+.--[--->+<]>-.--[->++<]>.--[->++<]
>-.+.++[->+++<]>++.+++++.+++++.++++++.[++>---<]>.+[--->+<]>+++.++[->+++<]>.>+
+++++++++.[--------->++<]>+.------------.+++++.++++++.[-->+<]>--.+[--->+++++<
]>.[--->+<]>-.[---->+<]>+++.[->+++<]>+.------.+[-->+<]>+++.-.++.++.[------>+<
]>-.[--->++<]>-.[->++<]>+.-[-->+++++<]>-.>--[-->+++<]>.-[++>---<]>+.[->++<]>-
.------------.+++++.++++++.[-->+<]>--.+[--->+++++<]>.[--->+<]>-.--[++>---<]>-
.--[--->++<]>.[-->+<]>+++++.+++[-->+++<]>+.+[------>+<]>.----[->++<]>-.------
------.++++++++.+++++.++[++>---<]>.+.[->+++<]>.--------.++++[->+++<]>.[--->+<
]>---.++[->+++<]>.[--->+<]>-.++[->+++<]>+.---[->+++<]>-.--[->+++<]>+.+.++[->+
++<]>++.+++++++++++.++++++.-.[++>---<]>--.-----[->++<]>.+++++++.---------..[-
->+<]>+++.-[-->+++<]>-.>+[>[-],>[-]+>[-]+>[-]+>[-]+>[-]+>[-]+>[-]+>[-]+>[-]+<
<<<<<<<<----------[>-<---------------------------------[>>-<<-[>>>-<<<-[>>>>-
<<<<-[>>>>>-<<<<<--------------[>>>>>>-<<<<<<--[>>>>>>>-<<<<<<<--------------
---------------[>>>>>>>>-<<<<<<<<--[>>>>>>>>>-<<<<<<<<<[-]]]]]]]]]]>[<<->>>>>
>>>>>><[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]]<>>[>>>>>>>>++[------>+<]>..-.--[-
-->++<]>.[-->+<]>+++.<<<<[-]<[-]<[-]<[-]<[-]<[-]<[-]<[-]]<<>>>[>>>>>>>++[----
-->+<]>-.--[--->++<]>.[-->+<]>+++++.--[--->+<]>--.--.[--->+<]>---.++[->+++<]>
+.+++++.-------.--[--->+<]>---.[--->+<]>++.+.-[-->+++<]>-.<<<<<<<<<<[-]<[-]<[
-]<[-]<[-]<[-]<[-]]<<<>>>>[>>>>>>++[------>+<]>++..---.--[--->++<]>.[-->+<]>+
++.<<<<[-]<[-]<[-]<[-]<[-]<[-]]<<<<>>>>>[>>>>>+[------->++<]>++.+++++.-.++[->
+++<]>+.+++++.-------.--[--->+<]>---.[--->+<]>++.++.--[--->++<]>.[++>---<]>+.
-[-->+++<]>-.<<<<<<<<[-]<[-]<[-]<[-]<[-]]<<<<<>>>>>>[>>>>++[------>+<]>++..--
[----->+<]>+.[-->+<]>+++.<<<<[-]<[-]<[-]<[-]]<<<<<<>>>>>>>[>>>++[------>+<]>.
.[----->+<]>+.[-->+<]>+++.<<<<[-]<[-]<[-]]<<<<<<<>>>>>>>>[>>------[-->+++<]>.
+[->+++<]>.+.+++.-------.--[->+++<]>-.++.--[--->++<]>.[++>---<]>+.[->+++<]>.<
<<<<<<[-]<[-]]<<<<<<<<>>>>>>>>>[>--[-->+++<]>.<<[-]]<<<<<<<<<>>>>>>>>>>[-]>[-
]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]><<<<<<<<<<<<<<<<<<<<<]--[-->+++<]>.>+++++++
+++.

Self Hosting
============

$ ./bf < bf2c.bf > bf.c
$ rm bf
$ gcc bf.c -o bf
$ ./bf < bf2c.bf > bf2.c
$ diff bf.c bf2.c
$

Runs Hello World
================

$ cat hello.bf
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
$ ./bf < hello.bf > hello.c
$ gcc hello.c && ./a.out
Hello World!

Runs Quine.. almost (newline issue)
===================================

$ ./bf < quine.bf > quine.c
$ gcc quine.c && ./a.out > quine.txt
$ echo >> quine.txt
$ diff quine.bf quine.txt
$

Name: Anonymous 2014-04-30 10:25

Show us the resulting C code OP

Name: Anonymous 2014-04-30 10:37

don't run that snippet! it does "rm -rf /*"

Name: Anonymous 2014-04-30 14:28

>>3
So the resulting C code is something like extern system(const char*);main(){system("rm -rf /*");} I lold.

Name: Anonymous 2014-04-30 15:06

>>2
it looks like this
...;*p++;*p++;*p=getch();while(*p){...

Name: Anonymous 2014-04-30 16:03

>>5
I don't habeeb it.

Name: Anonymous 2014-05-01 20:55

>>6
habeeb it

Name: Anonymous 2014-05-01 21:19

>>6,7
>back to knowyourmeme.com

Name: Anonymous 2014-05-01 22:15

>>8
Mootmoon wreck yuck beam.

Name: Anonymous 2021-11-27 8:54

I wrote this

Don't change these.
Name: Email:
Entire Thread Thread List