diff --git a/turinglab/__main__.py b/turinglab/__main__.py index e93533a..7b6a88e 100644 --- a/turinglab/__main__.py +++ b/turinglab/__main__.py @@ -1,13 +1,13 @@ import sys -from turinglab.input import from_tur +from turinglab.input import from_file from turinglab.emulator import Emulator from turinglab.output import to_docx def main(): - tur, input_string, docx = sys.argv[1:] + program_file, input_string, docx = sys.argv[1:] - [program,_,_] = from_tur(tur) + program = from_file(program_file) tm = Emulator(program, input_string) diff --git a/turinglab/emulator.py b/turinglab/emulator.py index 6808c3f..aae7309 100644 --- a/turinglab/emulator.py +++ b/turinglab/emulator.py @@ -24,7 +24,7 @@ class Emulator(): symbol = self.tape[self.head] try: - symbol, direction, state = self.instructions[self.current_state][symbol] + symbol, direction, state = self.instructions[symbol][self.current_state] self.tape[self.head] = symbol self.current_state = state diff --git a/turinglab/input.py b/turinglab/input.py index 3c01bcb..755201d 100644 --- a/turinglab/input.py +++ b/turinglab/input.py @@ -46,4 +46,30 @@ def from_tur(filename): solution_dict[i][symbol] = action - return solution_dict, task, description \ No newline at end of file + return solution_dict, task, description + +def from_file(filename: str): + f = open(filename, "r") + + program = dict() + + for line in f: + symbol, *actions = line.replace("\n", "").split('\t') + + if symbol == " ": + symbol = "λ" + + program[symbol] = [] + + for action in actions: + new_symbol, direction, new_state = list(action) + + if new_symbol == "_": + new_symbol = 'λ' + new_state = int(new_state) - 1 + + program[symbol].append([new_symbol, direction, new_state]) + + f.close() + + return program \ No newline at end of file