Skip to content
James Kinley edited this page May 28, 2025 · 2 revisions

JKDev Turing Machine Simulator

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

For more comprehensive documentation, click here!

Install Dependencies

There aren't many, but just standard procedure:

pip install -r requirements.txt

Usage

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

Running Tests (Handy for modifying things)

pytest

(That's it!)

Clone this wiki locally