Site menu Programmable Turing Machine

Programmable Turing Machine

This is a programmable Turing Machine: type the program on the editor, and see it run! Press "Run" to run the program, "Stop" to stop, "Step" to run a single transition step, and "Reset" to restore to initial configuration.

The default program (a binary increment algorithm) pretty much illustrates the whole "language". It is very simple, one line per command, parameters separated by spaces. Anything after a # is ignored, so you add comments.

timer 750 500
tape .....0..
head -3
state start

t start     01. . . find_lsb
t find_lsb  01  . > find_lsb    # look for LSB
t find_lsb  .   . < carry       # found LSB
t carry     1   0 < carry       # bit=1: write 0
t carry     0.  1 > halt        # bit=0: write 1, halt

The tape command specifies the initial tape contents, and accepts a single string parameter. Each symbol is one character. The null symbol is the dot (.). The caracters '#' and space are not valid symbols.

The head command defines the initial position of the head on the tape. It accepts a single integer parameter. First position is zero, and Python-style negative positions are accepted (e.g. -1 points to the last position).

The optional state command sets the initial machine state. It accepts a single string parameter. State names cannot have spaces. If this command is absent, the initial state defaults to the very first state of the transition table.

The optional timer command regulates the simulation speed and takes two integer parameters. The first value is the pause (in ms) between transitions. The second value is the pause between steps within a transition. Default values are 750 and 500 respectively.

The t command specifies a row of the transition table. It takes five parameters: current state, input symbol(s), symbol to write, direction the head will be moved to, and next state.

Accepting multiple symbols in a single transition is a cosmetic extension to help compact the transition table. The option of not writing to the tape is useful only for these multi-input transitions, so it can be considered cosmetic as well.

Some sources define the Turing Machine such as every transition must move the tape head. Allowing the tape not to move is an extension. If you want your program to remain compatible with all machine flavors, do not use this extension.