migrate to export file of turing emulator

This commit is contained in:
Maxim Slipenko 2021-09-17 21:10:49 +03:00
parent 8d5b2d56ca
commit c2712885d5
3 changed files with 31 additions and 5 deletions

View File

@ -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)

View File

@ -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

View File

@ -47,3 +47,29 @@ def from_tur(filename):
solution_dict[i][symbol] = action
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