We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Turing Code

From Esolang
Jump to navigation Jump to search
Turing code
Designed by IamAfile
Appeared in 2026
Computational class Unknown
Reference implementation Unimplemented

Preface

This is a Turing-machine-like language created by IamAfile.

It is Turing-complete because it is designed according to the Turing machine model. Rather than merely "following" the model, it almost directly copies it.

Syntax

Initialization

set tape [1,2,3,"HB"]

Sets the cells at non-negative indices (0 to ∞).

set tape -[1,2,3,"HB"]

Sets the cells at negative indices (-1, -2, -3, ...).

set state A

Sets the initial state.

  • Uninitialized cells default to 0.
  • The tape is infinite.
  • Escape characters (`\`) are allowed inside strings.
  • The read/write head starts at index 0.
  • Cells can store numbers and strings.
  • Numbers and strings are different types and are compared strictly.

Rules

  • `state{Rule1|Rule2...}`
  • Each rule has the form `read,write,move,new_state`.
Field Meaning
read The symbol read
write The symbol to write
move Movement direction (`R` = right, `L` = left, `Z` = stay in place)
new_state The state to switch to
  • Multiple rules are separated by vertical bars (`|`).

Halting

Execution **halts** when no rule matches.

Execution also **halts** when the machine jumps to an **undefined** state.

After halting, the entire tape is printed, with leading and trailing zeros (the number 0) removed. This is only for aesthetics and to keep your terminal from becoming huge.

Nondeterministic Turing machine

Updated at UTC+8 on November 22 and replaces the `rule priority` entry.

When multiple rules match at the same time, each matching rule produces a branch, and the interpreter searches using a queue (breadth-first):

  • Each time, take a branch from the front of the queue and execute one step.
  • If a branch has no matching rule (or jumps to an undefined state), that branch halts.
  • The tape of the first branch to halt is printed, and the program ends.
  • If the queue becomes empty and no branch has halted, output `REJECT`.

Breadth-first search guarantees that, when multiple branches can halt, the one with the fewest steps is printed. If the step counts are the same, the left-to-right order of the rules decides.

Random Turing machine

Updated at UTC+8 on November 22.

When multiple rules match at the same time, the Turing machine randomly selects one rule to execute, with uniform probability. The result of each run may differ.

The halting condition of an RTM is the same as that of a DTM: no matching rule or an undefined state. Since only one path runs each time, there is no "queue exhaustion." The result of each run may differ, which is the expected behavior of an RTM.

File header

To use a nondeterministic Turing machine, write `!!NDTM` at the beginning of the file. For a deterministic Turing machine, write `!!DTM` at the beginning of the file. For a random Turing machine, write `!!RTM` at the beginning of the file.

If you do not write one, the interpreter will report an error! 😱😱😱😱

If multiple rules match in a DTM, the interpreter will report an error! 😱😱😱😱

If multiple file headers appear, the interpreter will report an error! 😱😱😱😱

Comments

!!DTM
# I am a comment. I'm Six Seven.
(*1 line
two lines
3 lines*)

#It can be used for drawing, which is super cool!!!
##    ##    ###
##    ##    ###
##    ##
########    ###
########    ###
##    ##    ###
##    ##    ###
##    ##    ###

Identifiers

State names must be valid identifiers.

Identifiers may start with `_` but may not start with a digit.

Allowed identifier characters: `a`–`z`, `A`–`Z`, `0`–`9`, and `_`.

Errors

  • A character in an illegal position
  • A state name that is not a valid identifier
  • Unclosed parentheses
  • An unclosed block comment
  • A string with missing or unclosed quotation marks
  • Whitespace between a state name and the left curly brace

Examples

Binary counter (non-halting)

!!DTM
set tape [2]
set state A

A{0,1,R,Back|1,0,L,B|2,2,L,A}

B{1,0,L,B|0,1,R,Back}

Back{1,1,R,Back|0,0,R,Back|2,2,Z,A}

Binary counter (halting)

!!DTM
set tape [2]
set tape -[3,0,0,0,0,0,2]
set state A

A{0,1,R,Back|1,0,L,B|2,2,L,A}

B{1,0,L,B|0,1,R,Back}

Back{1,1,R,Back|0,0,R,Back|2,2,Z,A}

Notes

Updated at UTC+8 on November 22.

A Turing machine has no step limit, so your program may loop forever. You may need to search manually.

For an NDTM, if none of its branches halt, you still need to judge for yourself.

There is no other way. I have no ideas left, so figure it out yourselves.