Crates.io | ksplang |
lib.rs | ksplang |
version | 0.1.0 |
source | src |
created_at | 2024-02-19 06:48:42.7576 |
updated_at | 2024-02-19 06:48:42.7576 |
description | A ksplang interpreter |
homepage | https://ksp.mff.cuni.cz/viz/ksplang |
repository | https://github.com/ksp/ksplang |
max_upload_size | |
id | 1144833 |
size | 10,147,916 |
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 sizegit clone https://github.com/ksp/ksplang.git
ksplang
directory, run cargo build -p ksplang-cli --release
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.