Decimal
A stack language spelt with ten digits and the letter D. Any other character in the source is printed.
aaronryank · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 5 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Decimal, also called 09D, writes everything in digits. A command is one digit, and the digits after it are its arguments. Arguments whose length can vary, such as a number or a string, end with D. Strings are written as three-digit character codes, so 072101 is He.
Read the story
Instead of always working on the top of the stack, commands work at the Default Stack Index, the DSI. Pushing moves the DSI to the new value; command 0 can point it anywhere. Values carry a type, INT, CHAR or STRING, which decides how they print.
The machine
| Code | Does |
|---|---|
0nD | Set the DSI to n |
1tvD | Push value v of type t (1 INT, 2 CHAR, 3 STRING) |
2 | Pop the value at the DSI |
301 310 300 311 | Print the DSI; read a character; copy the DSI; copy input to output |
4nD | Math on the two values at the DSI: 1 +, 2 -, 3 *, 4 /, 5 %, 6 to 10 bitwise, 12 ==, 13 != |
5 … 5 | Run the part between if the DSI is not 0 |
61 62 | Move the DSI to memory; copy it back |
81D | Read a number |
9nD | Mark jump n the first time, jump back to it after that; 90D ends |
At the end of the input a read gives the character 255.
Example
In the third program = is not a command, so it is printed between the two prints of 42.
In the third program = is not a command, so it is printed between the two prints of 42. The last one is the cat from esolangs.org. It marks jump 1, reads a character, copies it, compares the copy with 255 and leaves through 90D when they match. Otherwise it pops the comparison, prints the character, pops it and jumps back.
Patterns it teaches
- Stack machines: with a movable index instead of a fixed top.
- Encoding tricks: text as runs of three-digit codes.
See also
Stack-based
Write your own in Run Convert a program from Decimal
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: decimal.
Command line
shib run decimal -e '11050D 11050D 41D 301'shib manual decimalSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/decimal.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org