Skip to content

Instantly share code, notes, and snippets.

@hrkt
Last active December 19, 2015 03:59
Show Gist options
  • Save hrkt/5894019 to your computer and use it in GitHub Desktop.
Save hrkt/5894019 to your computer and use it in GitHub Desktop.
Brainf*ck language to Exclamation language converter.
#!/usr/bin/python
"""
Brainf*ck langage to Exclamation language converter.
30 6 2013 Hiroki Ito
Exclamation programs can be translated into Brainf*ck using these substitutions
exclamation bf C
! + ++*ptr;
!! > ++ptr;
!!! < --ptr;
!!!! - --*ptr;
!!!!! . putchar(*ptr);
!!!!!! , *ptr=getchar();
!!!!!!! [ while (*ptr) {
!!!!!!!! ] }
"""
from __future__ import with_statement
import sys
if(1 == len(sys.argv)):
print "usage bf2ec brainfuck_filename"
sys.exit(0)
with open(sys.argv[1]) as bf_file:
buf = ""
for line in bf_file:
if(len(line) == 0 or line[0] == '#' or line[0] == '\n'):
continue
# print line.strip()
for c in line:
if '+' == c:
buf += "! "
elif '>' == c:
buf += "!! "
elif '<' == c:
buf += "!!! "
elif '-' == c:
buf += "!!!! "
elif '.' == c:
buf += "!!!!! "
elif ',' == c:
buf += "!!!!!! "
elif '[' == c:
buf += "!!!!!!! "
elif ']' == c:
buf += "!!!!!!!! "
else:
pass
print buf
M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment