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.
S
S is an esoteric programming language made by User:Dragoneater67 in 2026. It was inspired by six seven and Perl.
Overview
The program is a sequence of instructions executed left-to-right, it halts after the last instruction was executed. There is a deque of strings, which has a direction bit initialized to 0, if it is 0, instructions push/pop, else, they inject/eject. There is also a hash table that maps strings to strings.
| Instruction | Description |
|---|---|
string |
Push/inject a string, which has to be wrapped in double quotes unless it does not contain does not contain commands within it. |
! |
Flip direction bit. |
^ |
Pop/Eject a string and execute it as S code. |
$ |
Pop/Eject 2 strings and assign the first string to the second string. |
@ |
Pop/Eject a string and push/inject the string assigned to it if there is one, else push/inject an empty string. |
. |
Pop/Eject a string and output it. |
, |
Input a string and push/inject it. |
Popping/Ejecting an empty deque returns an empty string. Unmatched double quotes get automatically matched when an instruction is found.
Computational class
S is Turing complete since it can simulate UT19. The program starts with each character of the initial word getting pushed individually, followed by:
"a"_a$"!_b@_c@!"a$"b"_b$"!_d@_d@!"b$"c"_c$"!_H@_d@!"c$"d"_d$"!_a@_a@_r@!"d$"e"_e$"!_g@_i@!"e$"f"_f$"!_h@_i@!"f$"g"_g$"!_j@_j@!"g$"h"_h$"!_k@_j@!"h$"i"_i$"!_H@_j@!"i$"j"_j$"!_e@_f@!"j$"K"_K$"!_f@_e@_r@!"K$"l"_l$"!_n@_n@_n@_n@!"l$"m"_m$"!_o@!"m$"n"_n$"!_p@_p@!"n$"o"_o$"!_p@_q@!"o$"p"_p$"!_l@_m@!"p$"q"_q$"!_l@_l@_l@_l@!"q$"r"_r$"!!"r$"H"_H$"!_H@!"H$"!@^.!x@^"x$x@^
Moreover, S would be Turing complete if the ! command is removed, i.e. if the deque was instead replaced with a stack, since the ~:!()^ subset of Underload can be compiled into S. The compiled program begins by assigning each parenthesized subprogram with its own name in the hashmap to avoid the use of quotation marks later on. Inside these definitions and in the main section of the program, each instruction is replaced with the following:
(...) = <name that corresponds to parenthesized subprogram>@ ~ = _$__$_@__@ : = _$_@_@ ! = @^ ^ = ^
As long as neither _ nor __ are used as a name and there are no other name collisions within the program, the S deque directly simulates the Underload stack. For example, (!)((:^):^)~^ would translate to the following:
"@^"a$"_$_@_@^"b$"b@_$_@_@^"c$a@c@_$__$_@__@^
Here is a breakdown of the above compilation:
" @^ " a $ // assign (!) to a " _$_@_@ ^ " b $ // assign (:^) to b " b@ _$_@_@ ^ " c $ // assign ((:^):^) to c a@ c@ _$__$_@__@ ^ // main program
Examples
XKCD Random Number
4.
Hello, world!
"Hello, world!".
Truth machine
,"1.1@^"1$"0."0$@^
Infinite loop
"l@^"l$l@^
Cat program
",.l@^"l$l@^
Self-interpreter
,^
Looping counter
"*.^*@"*$" .n@"n$"*@^_@^"_$n@_@^
Implementation
An implementation in Python:
import collections, re, sys
def tokenize_program(program):
tokens = []
while program:
maybe_string = re.match(r'"[^"]*"|"[^"!^$@.,]*(?=[!^$@.,][^"]*$)|[^"!^$@.,]+', program, re.DOTALL)
if maybe_string is None:
tokens.append(program[0])
program = program[1:]
continue
tokens.append(maybe_string[0])
program = program[maybe_string.end():]
return tuple(tokens)
def interpreter(program, input_iter):
hashmap, deque = collections.defaultdict(str), collections.deque()
direction_bit = True
current_program = tokenize_program(program)
while current_program:
current_instruction, current_program = current_program[0], current_program[1:]
if current_instruction not in ('!', '^', '$', '@', '.', ','):
(deque.append if direction_bit else deque.appendleft)(current_instruction.strip('"'))
if current_instruction == "!":
direction_bit = not direction_bit
if current_instruction == "^":
current_program = tokenize_program((deque.pop if direction_bit else deque.popleft)()) + current_program
if current_instruction == "$":
key = (deque.pop if direction_bit else deque.popleft)()
hashmap[key] = (deque.pop if direction_bit else deque.popleft)()
if current_instruction == "@":
(deque.append if direction_bit else deque.appendleft)(hashmap[(deque.pop if direction_bit else deque.popleft)()])
if current_instruction == ".":
print((deque.pop if direction_bit else deque.popleft)(), end="")
if current_instruction == ",":
(deque.append if direction_bit else deque.appendleft)(next(input_iter))
interpreter(sys.stdin.read(), iter(sys.argv[1:]))