The Yen programming language

YEN Programming Language

YEN is a modern, statically-typed systems programming language with a focus on simplicity, safety, and performance.

Features

Quick Start

Building

mkdir build && cd build
cmake ..
make

This will create two executables:

Hello World

print "Hello, World!";

Run with:

./yen hello.yen

Language Features

Variables and Types

// Mutable variable
var x = 10;

// Immutable variable
let y = 20;

// Type annotations
var name: string = "YEN";
let count: int = 42;

Functions

func add(a: int, b: int) -> int {
    return a + b;
}

func greet(name: string) {
    print "Hello, " + name;
}

Lambda Expressions

let square = |x| x * x;
print square(5);  // 25

// With closures
var multiplier = 10;
let multiply = |x| x * multiplier;
print multiply(5);  // 50

Pattern Matching

var x = 42;

match (x) {
    0 => print "zero";
    1..10 => print "single digit";
    10..=100 => print "two digits";
    _ => print "other";
}

Range Expressions

// 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 Statements

{
    defer print "Cleanup!";
    defer print "More cleanup!";
    print "Working...";
}
// Output:
// Working...
// More cleanup!
// Cleanup!

Assertions

assert(x > 0, "x must be positive");

Classes and Structs

class Person {
    let name;
    let age;

    func greet() {
        print "Hello, I'm " + this.name;
    }
}

struct Point {
    x;
    y;
}

Standard Library

YEN comes with a comprehensive standard library:

Core Library

core_is_int(42)           // Type checking
core_to_string(123)       // Type conversion

Math Library

math_sqrt(16)             // 4.0
math_pow(2, 3)            // 8.0
math_random()             // Random [0, 1)
math_PI                   // 3.14159...

String Library

str_upper("hello")        // "HELLO"
str_split("a,b,c", ",")   // ["a", "b", "c"]
str_replace(text, "old", "new")

Collections Library

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 & Filesystem

io_write_file("file.txt", "content")
var content = io_read_file("file.txt")

fs_exists("file.txt")     // true/false
fs_create_dir("mydir")

Time Library

var timestamp = time_now()
time_sleep(1000)          // Sleep 1 second

Crypto Library

crypto_xor(data, key)     // XOR cipher
crypto_hash("text")       // Hash function
crypto_random_bytes(16)   // Random bytes

Encoding Library

encoding_base64_encode("text")
encoding_hex_encode("data")

Logging

log_info("Information message")
log_warn("Warning message")
log_error("Error message")

Environment Variables

env_set("MY_VAR", "value")
var val = env_get("MY_VAR")

Process & Shell Execution

// 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")

Examples

See the examples/ directory for more examples:

Basic Examples

Library Examples

Shell & System Examples

Platform-Specific Examples

Building with LLVM (Optional)

To build the compiler with LLVM support:

  1. Install LLVM 17+
  2. Set LLVM_DIR in CMakeLists.txt if needed
  3. Build as normal

The compiler (yenc) will be built if LLVM is detected.

Requirements

License

This project is open source. See LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues.

Disclaimer

This is an educational project demonstrating language implementation concepts. While functional, it is not intended for production use without further development and testing.