Skip to content

Instantly share code, notes, and snippets.

@bgnori
Created April 26, 2012 14:03
Show Gist options
  • Save bgnori/2499836 to your computer and use it in GitHub Desktop.
Save bgnori/2499836 to your computer and use it in GitHub Desktop.
+++[>+++++<-]>[>+>+++>+>++>+++++>++<[++<]>---]>->-.[>++>+<<--]>--.--.+.>>>++.<<
.<------.+.+++++.>>-.<++++.<--.>>>.<<---.<.-->-.>+.[+++++.---<]>>[.--->]<<.<+.+
+.++>+++[.<][.]<++.
import sys
fname = sys.argv[1]
f = open(fname)
source = f.read()
f.close()
header = """
#include<stdio.h>
int main(int argc, char**argv){
char array[30000];
char *ptr=array;
"""
footer = """
return 0;
}
"""
mapping = {
'>': "++ptr;",
'<': "--ptr;",
'+': "++*ptr;",
'-': "--*ptr;",
'.': "putchar(*ptr);",
',': "*ptr=getchar();",
'[': "while (*ptr) {",
']': "}",
}
outname = fname[:-2]+'c'
f = open(outname, 'w')
f.write(header)
for c in source:
o = mapping.get(c, '');
f.write(o +'\n')
f.write(footer)
f.close()
+++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
helloworld: bf2c.o helloworld.o
gcc -o helloworld bf2c.o helloworld.o
bf2c.o: bf2c.c
gcc -c bf2c.c
helloworld.o: helloworld.c
gcc -c helloworld.c
helloworld.c: helloworld.bf bf2c.py
python bf2c.py helloworld.bf
another: bf2c.o another.o
gcc -o another bf2c.o another.o
bf2c.o: bf2c.c
gcc -c bf2c.c
another.o: another.c
gcc -c another.c
another.c: another.bf bf2c.py
python bf2c.py another.bf
@bgnori
Copy link
Author

bgnori commented Apr 26, 2012

bf2c.cは中身空・・・。(いらなかった)

@bgnori
Copy link
Author

bgnori commented Apr 26, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment