feat: add shift left and shift right

This commit is contained in:
2021-06-15 13:53:53 -04:00
parent 54cba4ebb5
commit 05fa55e800

View File

@@ -1,10 +1,17 @@
import sys
# create memory buffer
# create memory buffer and pointer
class Memory:
BUFFER_SIZE = 30_000
buffer = [0 for _ in range(BUFFER_SIZE)]
pointer = 0
@classmethod
def get_pointer(cls) -> int:
pass
# define bf commands
class Operation:
SHIFT_LEFT = "<"
SHIFT_RIGHT = ">"
INCREMENT = "+"
@@ -14,6 +21,7 @@ INPUT = ","
OPEN_LOOP = "["
CLOSE_LOOP = "]"
def main() -> None:
# get bf file location
file_location = None
if len(sys.argv) != 2:
@@ -24,7 +32,30 @@ else:
# open file
file = open(file_location, "r")
print(file.read(1))
while True:
operation = file.read(1)
if not operation:
break
# perform operation
perform_operation(operation)
file.close()
def perform_operation(operation: str) -> None:
if operation == Operation.SHIFT_LEFT:
Memory.pointer -= 1
elif operation == Operation.SHIFT_RIGHT:
Memory.pointer += 1
elif operation == Operation.INCREMENT:
pass
elif operation == Operation.DECREMENT:
pass
elif operation == Operation.OUTPUT:
pass
elif operation == Operation.INPUT:
pass
if __name__ == "__main__":
main()