A toy programming language written in Rust, featuring Rust-like syntax for educational purposes.
To build the project, you need to have Rust installed. You can install it from here.
Once you have Rust installed, you can build the project by running the following command:
./build.sh --release
The binary will be located in target/release/toy-rs.
To install toy-rs, you can use the following command.
./install.sh
To run the tests, you can use the following command.
./test.sh
toy-rs <filemame.toy>
toy-rs supports a subset of Rust-like syntax.
Variables are declared using the let keyword.
let x = 10;
let y = 20.5;
let message = "Hello";
let is_valid = true;Standard and compound assignment operators are supported.
let x = 10;
x += 5; // 15
x -= 2; // 13
x *= 2; // 26
x /= 2; // 13- Integers:
1,42,-10 - Floats:
3.14,0.5,-2.0 - Booleans:
true,false - Strings:
"Hello World"
Standard arithmetic operators are supported for Integers and Floats. Mixed-type arithmetic (e.g., Int + Float) is supported and results in a Float.
let sum = 5 + 10;
let product = 2.5 * 4;
let mixed = 10 + 2.5;Logical AND (&&) and OR (||) operators are supported. && has higher precedence than ||.
let valid = true && (false || true); // true
let check = 1 < 2 && 3 > 2; // trueFunctions are declared using fn. The last expression in a block or a function body is implicitly returned.
fn add(a, b) {
a + b
}
let result = add(10, 20);if and else expressions are supported. They return the value of the branch that was executed.
let x = 10;
let status = if x > 5 {
"Greater"
} else {
"Smaller"
};while loops are supported for repeated execution based on a boolean condition.
let i = 0;
while i < 5 {
i += 1;
}Single-line comments starting with // are supported.
// This is a comment
let x = 5; // Inline commenttoy-rs includes built-in functions for output.
print(args...): Prints arguments separated by spaces.println(args...): Prints arguments separated by spaces, followed by a newline.
print("The answer is", 42);
println(); // Just a newline
println("Done.");