Last active
December 19, 2015 03:59
-
-
Save hrkt/5894019 to your computer and use it in GitHub Desktop.
Brainf*ck language to Exclamation language converter.
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
#!/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