This Python module provides a simple and extensible Turing Machine emulator.
It is designed as an educational tool, and I plan to extend it to feature higher-level implementations (with functions such as seek etc.), as well as adding methods to load TMs from files.
For more comprehensive documentation, click here!
There aren't many, but just standard procedure:
pip install -r requirements.txtThis example can be found in
src/Example.py.
"""Example of using the TuringMachine module!"""
from TuringMachine import TM, TMState, TMStateType, TMDirection
# Define states
states = [
TMState("start", TMStateType.START)
.add_transition('a', 'one_a', 'a', TMDirection.RIGHT),
TMState("one_a")
.add_transition('b', 'one_b', 'b', TMDirection.RIGHT),
TMState("one_b")
.add_transition('a', 'one_b', 'a', TMDirection.RIGHT)
.add_transition('_', 'accept', '_', TMDirection.RIGHT),
TMState("accept", TMStateType.ACCEPTING)
]
tm = TM(
states=states,
tape=['a', 'b', 'a'],
implicit_reject=True
)
accepted = tm.run(verbose=True)
print("Final: ", tm.current_state, "Accepted:", accepted)pytest
(That's it!)