Skip to content

Instantly share code, notes, and snippets.

@primo-ppcg
Last active April 2, 2019 07:34
Show Gist options
  • Save primo-ppcg/eeefc41e61be32d8889073a98cd11a8b to your computer and use it in GitHub Desktop.
Save primo-ppcg/eeefc41e61be32d8889073a98cd11a8b to your computer and use it in GitHub Desktop.
brainfuck to C transpiler
#!/usr/bin/perl -p
# bf2c.pl
# a primitive brainfuck to C transpiler
#
# usage: perl bf2c.pl program.bf | gcc -O2 -o program -xc -
BEGIN {
%w = qw(
- t[p]--;
+ t[p]++;
< p--;
> p++;
[ while(t[p]){
] }
. putchar(t[p]);
, (c=getchar())==EOF||(t[p]=c);
);
print '#include <stdio.h>
unsigned char c, t[65536];
unsigned short p;
int main() {
'
}
s/\S/$w{$&}/ge;
print ' ';
END {
print '
}'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment