feat: add shift left and shift right
This commit is contained in:
73
dopey.py
73
dopey.py
@@ -1,30 +1,61 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
# create memory buffer
|
# create memory buffer and pointer
|
||||||
BUFFER_SIZE = 30_000
|
class Memory:
|
||||||
buffer = [0 for _ in range(BUFFER_SIZE)]
|
BUFFER_SIZE = 30_000
|
||||||
|
buffer = [0 for _ in range(BUFFER_SIZE)]
|
||||||
|
pointer = 0
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_pointer(cls) -> int:
|
||||||
|
pass
|
||||||
|
|
||||||
# define bf commands
|
# define bf commands
|
||||||
SHIFT_LEFT = "<"
|
class Operation:
|
||||||
SHIFT_RIGHT = ">"
|
SHIFT_LEFT = "<"
|
||||||
INCREMENT = "+"
|
SHIFT_RIGHT = ">"
|
||||||
DECREMENT = "-"
|
INCREMENT = "+"
|
||||||
OUTPUT = "."
|
DECREMENT = "-"
|
||||||
INPUT = ","
|
OUTPUT = "."
|
||||||
OPEN_LOOP = "["
|
INPUT = ","
|
||||||
CLOSE_LOOP = "]"
|
OPEN_LOOP = "["
|
||||||
|
CLOSE_LOOP = "]"
|
||||||
|
|
||||||
# get bf file location
|
def main() -> None:
|
||||||
file_location = None
|
# get bf file location
|
||||||
if len(sys.argv) != 2:
|
file_location = None
|
||||||
print("Invalid or missing arguments...")
|
if len(sys.argv) != 2:
|
||||||
sys.exit()
|
print("Invalid or missing arguments...")
|
||||||
else:
|
sys.exit()
|
||||||
file_location = sys.argv[1]
|
else:
|
||||||
|
file_location = sys.argv[1]
|
||||||
|
|
||||||
# open file
|
# open file
|
||||||
file = open(file_location, "r")
|
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()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user