Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyElkabetz committed Sep 16, 2021
1 parent b590ad1 commit 93fee4d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions brain_fuck.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import sys
import argparse

Expand Down Expand Up @@ -33,6 +32,8 @@ def brainfuck(text_script, memory_size=30000):

# save BrainFuck script length
n = len(bfscript)
if n == 0:
exit()

# verify for syntactical loop errors (check that all loops begins
# with a '[' and ends with a ']'). also create a loop map dictionary
Expand Down Expand Up @@ -111,18 +112,20 @@ def brainfuck(text_script, memory_size=30000):
parser = argparse.ArgumentParser(description='A Python BrainFuck interpreter implementation.')
# Arguments
parser.add_argument('-file', type=str,
help='The path to the .txt file you want to interpret with BrainFuck interpreter.')
help='The path to the file you want to interpret with BrainFuck interpreter.')
parser.add_argument('-memory_size', type=int, default=30000,
help='The size of memory being used (list length).')

args = parser.parse_args()
with open(args.file + '.txt', 'r') as file:
with open(args.file, 'r') as file:
text = file.read()
try:
print('Reading with BrainFuck...')
brainfuck(text, memory_size=args.memory_size)
except Exception as e:
print('Some problem occurred.')
except IOError as e:
print('Error in reading file: {}'.format(args.file))
exit()




Expand Down

0 comments on commit 93fee4d

Please sign in to comment.