fork download
  1. def read(unFile):
  2. with open(unFile) as f:
  3. return len(f.read())
  4.  
  5. def toBF(num):
  6. a = []
  7. while num > 0 and num != 1:
  8. b = 0
  9. for _ in range(3):
  10. b = 2*b + num % 2
  11. num //= 2
  12. a.append(b)
  13. return a
  14.  
  15. def compile(bf, fl):
  16. with open(fl, 'w') as c:
  17. print>>c, "#include <stdio.h>"
  18. print>>c, "char p[30000];"
  19. print>>c, "int main(){"
  20. for num in bf:
  21. if num == 0:
  22. print>>c, "p++;"
  23. elif num == 1:
  24. print>>c, "p--;"
  25. elif num == 2:
  26. print>>c, "*p++;"
  27. elif num == 3:
  28. print>>c, "*p--;"
  29. elif num == 4:
  30. print>>c, "putchar(*p);"
  31. elif num == 5:
  32. print>>c, "*p = getchar();"
  33. elif num == 6:
  34. print>>c, "while(*p){"
  35. else:
  36. print>>c, "}"
  37. print>>c, "return 0; }"
  38.  
  39. def main():
  40. from sys import argv
  41. compile(toBF(read(argv[1])),argv[2])
  42.  
  43. main()
  44.  
Runtime error #stdin #stdout 0.01s 4672KB
stdin
Standard input is empty
stdout
Standard output is empty