fork download
  1. # Sesos: https://github[dot]com/DennisMitchell/sesos
  2.  
  3. import sys
  4.  
  5. S = {'>': 'fwd %d',
  6. '<': 'rwd %d',
  7. '+': 'add %d',
  8. '-': 'sub %d',
  9. ',': 'get',
  10. '.': 'put',
  11. '[': 'jmp',
  12. ']': 'jnz'}
  13.  
  14.  
  15. I = sys.stdin.read()
  16.  
  17. # remove invalid operations
  18. t = I.replace('><','').replace('<>','').replace('+-','').replace('-+','')
  19. while t != I:
  20. I = t
  21. t = I.replace('><','').replace('<>','').replace('+-','').replace('-+','')
  22.  
  23. I = list(I)
  24.  
  25. r = ""
  26. n = 0
  27. while I:
  28. c = I.pop(0)
  29. if c in "><+-":
  30. if r == c:
  31. n += 1
  32. else:
  33. if r:print S[r] % n
  34. r = c
  35. n = 1
  36. elif c in ",.[]":
  37. if r:
  38. print S[r] % n
  39. r = ""
  40. n = 0
  41. print S[c]
  42. if I and ((c == "[" and I[0] == "]") or (c == "]" and I[0] == "[")):
  43. print "nop"
  44. else:
  45. # Ignore comments
  46. pass
  47.  
  48. if not I and r:
  49. print S[r] % n
  50.  
Success #stdin #stdout 0.02s 9024KB
stdin
[->+>+<<]++>[-<->]+<[>-<,]>[->+<]>
stdout
jmp
sub 1
fwd 1
add 1
fwd 1
add 1
rwd 2
jnz
add 2
fwd 1
jmp
sub 1
rwd 1
sub 1
fwd 1
jnz
add 1
rwd 1
jmp
fwd 1
sub 1
rwd 1
get
jnz
fwd 1
jmp
sub 1
fwd 1
add 1
rwd 1
jnz
fwd 1