Skip to content

jameskinley/JKDev-TuringMachineSim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.), as well as adding methods to load TMs from files.

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

About

Contains a lightweight, extensible API for simulating Turing Machines

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages