migrate to export file of turing emulator
This commit is contained in:
parent
8d5b2d56ca
commit
c2712885d5
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -46,4 +46,30 @@ def from_tur(filename):
|
||||
|
||||
solution_dict[i][symbol] = action
|
||||
|
||||
return solution_dict, task, description
|
||||
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
|
Loading…
Reference in New Issue
Block a user