Advertisement
bf17

BF shorthand to long

Mar 19th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. # python 3.4.3
  2. # convert BF shorthand code to standard BF code
  3. # this program can process 1+ or 2>>, but bf_l2s.py will not generate that shorthand
  4.  
  5. prevch=""
  6. nextch=""
  7. counter=1
  8. error_count=0
  9. command_set="<>+-[].,"
  10. num=""
  11.  
  12. file = open(input(("bf file: "), 'r')
  13.  
  14. print()
  15.  
  16. while True:
  17.     nextch=file.read(1)
  18.  
  19.     if(not nextch):
  20.         file.close()
  21.         break
  22.  
  23.     if(nextch.isnumeric()):
  24.         num = num + nextch
  25.     elif(nextch not in command_set):
  26.         error_count += 1
  27.     elif(num == ""):
  28.         print(nextch,end="")
  29.     else:
  30.         print(nextch * int(num), end="")
  31.         num=""
  32. print()
  33. print()
  34.  
  35. """
  36. Sample input BF code, Hello World implementations in the Esoteric Programming Language Wiki
  37.  
  38. ++++++++++[>+++++++>++++++++++>+++>+<
  39. <<<-]>++.>+.+++++++..+++.>++.<<++++++
  40. +++++++++.>.+++.------.--------.>+.>.
  41.  
  42.  
  43. bf_l2s.py returns:
  44.  
  45. 10+[>7+>10+>3+>+4<-]>++.>+.7+..3+.>++.<<15+.>.3+.6-.8-.>+.>.
  46.  
  47. 111 Commands
  48.  
  49. bf_s2l.py returns the original program (without formatting), and it runs too!
  50. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement