BRAIDGROUP
RESEARCH & DEV
3. Documentation

Quick Start

This guide gets you from zero to running Braid code in under five minutes. You need braidc installed — see the Installation page if you have not built it yet.

Hello World

Create a file named hello.br:

fn main() {
    print("Hello, Braid!")
}

Run it:

braidc run hello.br

Expected output:

Hello, Braid! Execution complete. Exit code: 0

Variables

fn main() {
    let x = 10
    let y = 3.14
    let name = "Braid"
    let flag = true

    print(x)
    print(y)
    print(name)
    print(flag)
}

Functions

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

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

fn main() {
    greet("World")
    let sum = add(10, 20)
    print(sum)       // 30
}

If and While

fn main() {
    let x = 5

    if x > 3 {
        print("x is greater than 3")
    } else {
        print("x is 3 or less")
    }

    let i = 0
    while i < 5 {
        print(i)
        i = i + 1
    }
    // prints 0, 1, 2, 3, 4
}

Structs

struct Point {
    x: int
    y: int
}

fn main() {
    let p = Point { x: 10, y: 20 }
    print(p.x)     // 10
    print(p.y)     // 20
}

Building to Bytecode

Compile your source into a .bx bytecode artifact:

braidc build hello.br -o hello.bx

Then run the bytecode directly:

braidc run hello.bx

Inspecting the AST

See how the compiler understands your code:

braidc ast hello.br

Generating C Code

Emit the C code that braidc generates internally:

braidc ccodegen hello.br

Pipeline Reference

CommandDescription
braidc parse file.brTokenize and parse, validate syntax
braidc ast file.brBuild and output the AST
braidc ir file.brLower AST to Braid IR
braidc ccodegen file.brGenerate C source code
braidc build file.br -o out.bxPackage as .bx bytecode
braidc run file.brFull pipeline to execution