Created
April 26, 2012 14:03
-
-
Save bgnori/2499836 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+++[>+++++<-]>[>+>+++>+>++>+++++>++<[++<]>---]>->-.[>++>+<<--]>--.--.+.>>>++.<< | |
.<------.+.+++++.>>-.<++++.<--.>>>.<<---.<.-->-.>+.[+++++.---<]>>[.--->]<<.<+.+ | |
+.++>+++[.<][.]<++. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://en.wikipedia.org/wiki/Brainfuck