Starry
A stack language written in spaces and six punctuation marks. The program looks like a night sky.
Yutaka Hara, 2008 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 3 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Yutaka Hara designed Starry in 2008 for his Japanese book on building strange languages in Ruby. It is the book's worked example, so it is small and regular.
Read the story
The trick is that the symbol says what kind of command it is, and the number of spaces before it says which one. Five spaces and a + push 0, six push 1. Two spaces and a * multiply. Newlines and all other characters are ignored, so a long run of spaces can carry on across lines.
A finished program is mostly blank space with a few +, * and . scattered over it, like stars.
The machine
One stack of integers. An instruction is a run of n spaces and one symbol.
| Symbol | Does |
|---|---|
+ | n=1 dup, 2 swap, 3 rotate (a b c becomes b c a), 4 drop, n>=5 push n-5; n=0 is invalid |
* | Pop y, then x; push x+y, x-y, x*y, x/y or x mod y for n mod 5 = 0, 1, 2, 3, 4 |
. | Pop and print: as a number if n is even, as a character if n is odd |
, | Read: a number if n is even, a byte if n is odd |
` | Mark label n | |
' | Pop; if not 0, jump to label n |
Division and mod are floored, as in Ruby. Popping an empty stack gives 0. An invalid opcode, a division by zero or a jump to a missing label stops the program.
Example
Eight spaces and + push 3.
Eight spaces and + push 3. ` with no spaces marks label 0. + duplicates and . prints it as a number. Six spaces and + push 1, * subtracts, + duplicates, and ' jumps back to label 0 while the value is not 0.
Patterns it teaches
- Stack machines: every value passes through one stack.
- Encoding tricks: the opcode is a count of spaces, not a character.
- Turing completeness: unbounded values plus a conditional jump simulate a two-register Minsky machine.
Try this
- Print
42as a number: push 6 and 7, multiply, print. - Change the example to count down from 9.
- Hard: write a cat that copies bytes until the input ends.
Further
See also
Stack-based
Write your own in Run Convert a program from Starry
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: starry.
Command line
shib run starry -e ' , .' --input 'a'shib manual starrySource
- Module
langs/stack/ports.js- Interpreter
langs/stack/starry.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org