Add a way to run the programs
This commit is contained in:
parent
ca314ee310
commit
2ed9adcc93
2
README
2
README
|
@ -10,3 +10,5 @@ To produce a tape usable by the step command, input your tape in the form:
|
|||
|
||||
Which says there is a tape with 5 cells, second from right being 1 and all
|
||||
others being 0, and the tape head is in the middle of this tape
|
||||
|
||||
You can also run the compiled result by giving sf2xed.py the -r argument.
|
||||
|
|
26
sf2xed.py
26
sf2xed.py
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
import enum
|
||||
import sys
|
||||
from collections import namedtuple
|
||||
|
||||
class actions(enum.Enum):
|
||||
|
@ -264,7 +265,26 @@ def process_tape(tape, processed):
|
|||
|
||||
return ' '.join(processed_tape) + ' z'
|
||||
|
||||
def run_replacements(replacements, processed_tape):
|
||||
while True:
|
||||
made_replacement = False
|
||||
for start, end in replacements:
|
||||
if start in processed_tape:
|
||||
processed_tape = processed_tape.replace(start, end)
|
||||
made_replacement = True
|
||||
break
|
||||
|
||||
if not made_replacement:
|
||||
break
|
||||
|
||||
print(processed_tape)
|
||||
|
||||
def main():
|
||||
if len(sys.argv) == 2 and sys.argv[1] == '-r':
|
||||
run = True
|
||||
else:
|
||||
run = False
|
||||
|
||||
program = input('program: ')
|
||||
|
||||
start_noreachability, states_noreachability = turingify(parse_smallfuck(program))
|
||||
|
@ -278,7 +298,11 @@ def main():
|
|||
tape = input('tape: ')
|
||||
if tape == '': break
|
||||
tape = tape.split(' ')
|
||||
print(process_tape(tape, processed))
|
||||
processed_tape = process_tape(tape, processed)
|
||||
print(processed_tape)
|
||||
|
||||
if run:
|
||||
run_replacements(replacements, processed_tape)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue