Skip to content

Instantly share code, notes, and snippets.

@hrkt
Created June 30, 2013 05:32
Show Gist options
  • Save hrkt/5893987 to your computer and use it in GitHub Desktop.
Save hrkt/5893987 to your computer and use it in GitHub Desktop.
Exclamation language to brainf*ck language converter.
#!/usr/bin/python
from __future__ import with_statement
import sys
"""
Exclamation language to Brainf*ck langage 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) {
!!!!!!!! ] }
"""
if(1 == len(sys.argv)):
print "usage ec2bf exclamation_filename"
sys.exit(0)
with open(sys.argv[1]) as ec_file:
tokens = ec_file.read().split(" ")
buf = ""
for t in tokens:
if '!' == t:
buf += '+'
elif '!!' == t:
buf += '>'
elif '!!!' == t:
buf += '<'
elif '!!!!' == t:
buf += '-'
elif '!!!!!' == t:
buf += '.'
elif '!!!!!!' == t:
buf += ','
elif '!!!!!!!' == t:
buf += '['
elif '!!!!!!!!' == t:
buf += ']'
else:
pass
print buf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment