A stack-based programming language with 33 instructions, independently designed by 33 people.
This is an implementation of ksplang, the best programming language (as proven by the logic of a Czech children's story).
The famous Czech children's story Jak si pejsek s kočičkou dělali k svátku dort (English translation) by Josef Čapek teaches that you can bake the best cake by adding many good things into it. Yes, that is definitely the correct interpretation. We have decided to prove this experimentally, with a programming language.
We have done this within KSP, a Czech programming competition for high-school students. Within the first series of tasks of the 36th year, we have asked each competitor for a single original instruction for a stack-based language. The result is ksplang, and you are currently looking at its reference implementation in Rust.
This repository includes a ksplang
executable which can be used to run ksplang programs. Input is given on the standard input as whitespace-separated numbers (or text).
./ksplang program.ksplang < input.txt > output.txt
program.ksplang – the ksplang program:
pop ++
input.txt – the input stack:
41 12
output.txt – the result:
42
The interpreter can also be used in text mode, which translates input from text to numbers and output from numbers to text (as Unicode code points). You can also do this only for input or output with --text-input
and --text-output
, respectively.
echo -n "aaa" | ./ksplang -t program.ksplang
# prints "ab"
--stats
(-s
) - print statistics on stderr--max-stack-size
(-m
) - set the maximum stack size
- Clone the repository:
git clone https://github.com/ksp/ksplang.git
- Within the
ksplang
directory, runcargo build -p ksplang-cli --release
- You can now run
target/release/ksplang-cli
An online version of the interpreter with a simple stepping debugger lives on the KSP webpage.
If you have improvements to the reference implementation, the tooling, or the descriptions, feel free to create an issue or a pull request.
No changes to the language are allowed as the language is perfect.
This code is available under the MIT License. See the LICENSE file for details.