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.brExpected output:
Hello, Braid! Execution complete. Exit code: 0Variables
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.bxThen run the bytecode directly:
braidc run hello.bxInspecting the AST
See how the compiler understands your code:
braidc ast hello.brGenerating C Code
Emit the C code that braidc generates internally:
braidc ccodegen hello.brPipeline Reference
| Command | Description |
|---|---|
braidc parse file.br | Tokenize and parse, validate syntax |
braidc ast file.br | Build and output the AST |
braidc ir file.br | Lower AST to Braid IR |
braidc ccodegen file.br | Generate C source code |
braidc build file.br -o out.bx | Package as .bx bytecode |
braidc run file.br | Full pipeline to execution |