JSONseq
A program is a JSON file, and every instruction is an object with a word in it.
Turing complete: unknown · ●○○ easy · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
JSONseq turns JSON, a format made for data, into code. The file holds one object with a sequence, an array of words. Each word is an object that names itself in wd-name and takes up to four arguments, arg1 to arg4. There are 12 words, and the specification says you cannot make more. Its interpreter is written in Node.js.
The machine
| Word | Does |
|---|---|
SETVAR | Set variable arg1 to the value arg2 |
CPVAR | Copy variable arg1 into arg2 |
PRNT | Print the variable PRNT-OUT-DT, or the variable named in arg1 |
INP | Nothing; the specification says it does not work |
ADD SUB MUL DIV | Put arg1 op arg2 into the variable arg3 |
ASSERT | Run the words in arg4 if arg1 compares to arg2 by arg3 |
JUMP | Go to word number arg1, counted from 0 |
LOOP | Run the words in arg4 a number of times, with ITERATION-N counting |
EXIT | End the program |
The comparisons are ls, ls-eq, eq, gr and gr-eq. Values keep their JSON type and the operators are those of JavaScript, so ADD on two strings joins them. The specification leaves open which way CPVAR copies and how LOOP counts. CPVAR copies arg1 into arg2, and LOOP runs arg2 times while ITERATION-N goes from arg1 in steps of arg3.
Example
The Hello world keeps its text in PRNT-OUT-DT, the variable a bare PRNT prints.
The Hello world keeps its text in PRNT-OUT-DT, the variable a bare PRNT prints.
The truth machine has its input written into the program as "0". The ASSERT finds it equal to ZERO, prints it and exits. With "1" it would fall through to PRNT ONE and JUMP 4, which goes back to that PRNT for ever.
Patterns it teaches
- Camouflage: the program passes for a data file.
Further
See also
Also in Camouflage
Write your own in Run Convert a program from JSONseq
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: jsonseq.
Command line
shib run jsonseq -e '{
"sequence": [
{ "wd-name": "SETVAR", "arg1": "PRNT-OUT-DT", "arg2": "Hello, World!\n" },
{ "wd-name": "PRNT" },
{ "wd-name": "EXIT", "arg1": 0 }
]
}'shib manual jsonseqSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/jsonseq.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org