#scripting-language #scripting #scripting-engine #control-flow

bin+lib krab

Krab is a simple and minimalistic interpreted programming language written in Rust

4 releases

0.1.3 Apr 13, 2023
0.1.2 Apr 11, 2023
0.1.1 Apr 11, 2023
0.1.0 Apr 11, 2023

#748 in Embedded development

MIT/Apache

95KB
2.5K SLoC

Krab

Krab Icon

Krab is a simple and minimalistic interpreted programming language written in Rust. It has almost no functionality and it is not meant to be used for any serious purpose. It was created as a fun experiment to see how compact and simple a programming language can be.

Features

  • Basic types: int, float, bool, string
  • Variables: let and const
  • Control flow: if, while, break, continue
  • Functions: fn and return
  • Expressions: arithmetic, logical and comparison operators
  • Native function: print()

Syntax

Krab has a very simple syntax that resembles Rust. Here are some examples:

// Declare a variable with explicit type
let x: int = 42;

// Declare a variable with implicit type
let y = 3.14;

// Declare a constant
const z = true;

// Define a function
fn add(a: int, b: int) -> int {
    // Return without semicolon
    a + b 
}

// Call a function
let result = add(x, 8);

// Print to stdout
print(result);

// Use if as an expression
let max = if x > y {
    x // No semicolon here!
} else {
    y // Or here!
};

// Use while loop for iteration
let i = 0;
while i < 10 {
    print(i);
    i = i + 1;
}

Usage

To use Krab, you need to install Rust and run cargo run in the project directory. This will launch a REPL where you can write Krab code interactively. You can also execute a .krab file by passing its path to the REPL. For example:

$ cargo run
- Krab 0.1 REPL
Type 'exit' to leave or 'clear' to clear the terminal
> ./code.krab
Hello from Krab!
> 5 + 5
10
> 

Why Krab?

There is no good reason to use Krab over any other programming language. It is just a toy language that was made for fun and learning. If you are looking for an embedded scripting language for your Rust code, you should check out rhai instead.

However, Krab is better than JavaScript! (but slower)

Dependencies

~0.3–10MB
~58K SLoC