Add a python script to convert brainfuck source to an assembly file

This commit is contained in:
Pedro de Oliveira 2014-08-15 22:21:29 +01:00
parent f49cadd862
commit c6502994b5
1 changed files with 21 additions and 0 deletions

21
zxbrainfuck/bf2data.py Normal file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
if len(sys.argv) < 2:
sys.stderr.write("Usage: %s source.bf" % sys.argv[0])
sys.exit(1)
allowed_chars = (">", "<", "+", "-", ".", ",", "[", "]")
file = open(sys.argv[1], 'r')
print "ORG $9400"
sys.stdout.write("src db \"")
for char in file.read():
if char in allowed_chars:
sys.stdout.write(char)
else:
continue
print "\", 0"