YEN is a modern, statically-typed systems programming language with a focus on simplicity, safety, and performance.
mkdir build && cd build
cmake ..
make
This will create two executables:
yen - The interpreteryenc - The compiler (requires LLVM 17+)print "Hello, World!";
Run with:
./yen hello.yen
// Mutable variable
var x = 10;
// Immutable variable
let y = 20;
// Type annotations
var name: string = "YEN";
let count: int = 42;
func add(a: int, b: int) -> int {
return a + b;
}
func greet(name: string) {
print "Hello, " + name;
}
let square = |x| x * x;
print square(5); // 25
// With closures
var multiplier = 10;
let multiply = |x| x * multiplier;
print multiply(5); // 50
var x = 42;
match (x) {
0 => print "zero";
1..10 => print "single digit";
10..=100 => print "two digits";
_ => print "other";
}
// Exclusive range
for i in 0..5 {
print i; // 0, 1, 2, 3, 4
}
// Inclusive range
for i in 1..=5 {
print i; // 1, 2, 3, 4, 5
}
{
defer print "Cleanup!";
defer print "More cleanup!";
print "Working...";
}
// Output:
// Working...
// More cleanup!
// Cleanup!
assert(x > 0, "x must be positive");
class Person {
let name;
let age;
func greet() {
print "Hello, I'm " + this.name;
}
}
struct Point {
x;
y;
}
YEN comes with a comprehensive standard library:
core_is_int(42) // Type checking
core_to_string(123) // Type conversion
math_sqrt(16) // 4.0
math_pow(2, 3) // 8.0
math_random() // Random [0, 1)
math_PI // 3.14159...
str_upper("hello") // "HELLO"
str_split("a,b,c", ",") // ["a", "b", "c"]
str_replace(text, "old", "new")
list_push([1, 2], 3) // [1, 2, 3]
list_reverse([1, 2, 3]) // [3, 2, 1]
list_sort([3, 1, 2]) // [1, 2, 3]
io_write_file("file.txt", "content")
var content = io_read_file("file.txt")
fs_exists("file.txt") // true/false
fs_create_dir("mydir")
var timestamp = time_now()
time_sleep(1000) // Sleep 1 second
crypto_xor(data, key) // XOR cipher
crypto_hash("text") // Hash function
crypto_random_bytes(16) // Random bytes
encoding_base64_encode("text")
encoding_hex_encode("data")
log_info("Information message")
log_warn("Warning message")
log_error("Error message")
env_set("MY_VAR", "value")
var val = env_get("MY_VAR")
// Execute command and get exit code
var exit_code = process_exec("mkdir /tmp/test")
// Execute command and capture output
var files = process_shell("ls -la")
print files
// Get current directory
var dir = process_cwd()
// Change directory
process_chdir("/tmp")
// Execute with arguments
process_spawn("git", "status")
See the examples/ directory for more examples:
hello.yen - Hello Worldfibonacci.yen - Fibonacci sequencefeatures_demo.yen - Language features showcasemodern_features_demo.yen - Modern features democollections_demo.yen - Collections usagestring_demo.yen - String manipulationos_shell_simple.yen - Simple shell command examplesshell_commands.yen - Comprehensive shell operationssystem_automation.yen - System automation utilitiesTo build the compiler with LLVM support:
LLVM_DIR in CMakeLists.txt if neededThe compiler (yenc) will be built if LLVM is detected.
This project is open source. See LICENSE file for details.
Contributions are welcome! Please feel free to submit pull requests or open issues.
This is an educational project demonstrating language implementation concepts. While functional, it is not intended for production use without further development and testing.