Turimg

From Esolang
Jump to navigation Jump to search

Turimg is a minimalist language, meant to directly parallel how Turing machines work.

Environment

The environment of Turimg consists of an infinitely long tape, with each cell either being a 0 or a 1. On this tape is a pointer, which can be at any of these cells, however if it attempts to go out of bounds (e.g. negative cells or outside of the tape size of the interpreter) then the program will terminate. There is also a list of states, through which the program traverses through. These also determine how the pointer moves, and when it reads and writes data.

Overview

Every line is either a comment (shown with a preceding semicolon) or a state declaration. A state declaration may be of one of the following forms:

state	dir	set	next0	next1
state	dir	set	next

Each of these arguments must be seperated by tabs. What these arguments do is:

  • state refers to the name of the state, and can be any string.
  • dir is the next direction that the pointer should move, and can be either empty, in which case the pointer doesn't move at all, <, in which case the pointer moves left, and finally >, in which case the pointer moves right.
  • set is what value should be written to the tile. It can be 0, 1, . (which will output the bit to stdout) and , (which will read one bit of input from stdin and store it to the cell)
  • next is the next state that should be jumped to
  • next0 is the next state that should be jumped to if the initial value of the current cell is 0
  • next1 is the next state that should be jumped to if the initial value of the current cell is 1.

The order in which these are evaluated is the following: state -> set -> dir

Whenever the state halt is reached, the program stops execution.

Modes

There are two modes in the official Turimg interpreter: Binary mode (default) and ASCII Mode.

Binary mode directly takes binary input and outputs single bits. ASCII mode may be activated with the -ascii flag and takes every 8 outputted bits as an ASCII character code. It also converts input into it's corresponding ASCII code and sends those bits to stdin in order.

Example Programs

Hello, World!

;prints "Hello, World!" in ascii mode
;first initialize cell 0 with 0 and cell 1 with 1
set0	>	0	set1
set1	<	1	c0
;H
c0	>	.	c1
c1	<	.	c2
c2		.	c3
c3	>	.	c4
c4	<	.	c5
c5		.	c6
c6		.	c7
c7		.	c8
;e
c8	>	.	c9
c9		.	c10
c10	<	.	c11
c11		.	c12
c12	>	.	c13
c13	<	.	c14
c14	>	.	c15
c15	<	.	c16
;l
c16	>	.	c17
c17		.	c18
c18	<	.	c19
c19	>	.	c20
c20		.	c21
c21	<	.	c22
c22		.	c23
c23		.	c24
;l
c24	>	.	c25
c25		.	c26
c26	<	.	c27
c27	>	.	c28
c28		.	c29
c29	<	.	c30
c30		.	c31
c31		.	c32
;o
c32	>	.	c33
c33		.	c34
c34	<	.	c35
c35	>	.	c36
c36		.	c37
c37		.	c38
c38		.	c39
c39	<	.	c40
;,
c40		.	c41
c41	>	.	c42
c42	<	.	c43
c43	>	.	c44
c44		.	c45
c45	<	.	c46
c46		.	c47
c47		.	c48
; 
c48		.	c49
c49	>	.	c50
c50	<	.	c51
c51		.	c52
c52		.	c53
c53		.	c54
c54		.	c55
c55		.	c56
;W
c56	>	.	c57
c57	<	.	c58
c58	>	.	c59
c59	<	.	c60
c60	>	.	c61
c61		.	c62
c62		.	c63
c63	<	.	c64
;o
c64	>	.	c65
c65		.	c66
c66	<	.	c67
c67	>	.	c68
c68		.	c69
c69		.	c70
c70		.	c71
c71	<	.	c72
;r
c72	>	.	c73
c73		.	c74
c74		.	c75
c75	<	.	c76
c76		.	c77
c77	>	.	c78
c78	<	.	c79
c79		.	c80
;l
c80	>	.	c81
c81		.	c82
c82	<	.	c83
c83	>	.	c84
c84		.	c85
c85	<	.	c86
c86		.	c87
c87		.	c88
;d
c88	>	.	c89
c89		.	c90
c90	<	.	c91
c91		.	c92
c92	>	.	c93
c93	<	.	c94
c94		.	c95
c95		.	c96
;!
c96		.	c97
c97	>	.	c98
c98	<	.	c99
c99		.	c100
c100		.	c101
c101		.	c102
c102	>	.	c103
c103	<	.	c104
c104		.	c105
c105	>	.	c106
c106	<	.	c107
c107		.	c108
c108		.	c109
c109		.	c110
c110		.	c111
c111		.	halt

Cat program

;outputs it's input (works in binary and ascii mode)
in		,	out
out		.	in

Truth Machine

;only works in binary mode
;get input
in		,	test
;test input, goto end if it's 0 and loop if it's 1
test			end	loop
;output bit and go back to the same state, creating an infinite loop
loop		.	loop
;goto end and halt
end		.	halt

Interpreter

An intepreter for Turimg is available here