Created
May 5, 2017 13:17
-
-
Save ConorOBrien-Foxx/cca95c7d8c4c1a66b8aa3ecc2e379dd3 to your computer and use it in GitHub Desktop.
random BF transpiler
This file contains hidden or 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
#!/usr/bin/env bash | |
cat > "$1.c" << EOF | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <time.h> | |
int main(){ | |
srand(time(NULL)); | |
uint8_t t[65536] = {0}; | |
uint16_t p = 0; | |
int i; | |
EOF | |
while read -n1 char; do | |
case "$char" in | |
\>) echo '++p;';; | |
\<) echo '--p;';; | |
\+) echo '++t[p];';; | |
\-) echo '--t[p];';; | |
\,) echo 'i=getchar(),t[p]=i*(i>0);';; | |
\.) echo 'putchar(t[p]);';; | |
\[) echo 'while(t[p]){';; | |
\]) echo '}';; | |
\?) echo 't[p]=rand();';; | |
esac | |
done < "$1" >> "$1.c" | |
echo 'return 0;}' >> "$1.c" | |
cc -O3 -o "$1.out" "$1.c" && "./$1.out" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment