Created
June 30, 2013 05:32
-
-
Save hrkt/5893987 to your computer and use it in GitHub Desktop.
Exclamation language to brainf*ck 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 | |
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