Language

cruxLang

A domain-specific language for defining deterministic simulation worlds.

Overview

cruxLang is the high-level language for defining cruxOS worlds. It compiles to cruxIR (Intermediate Representation), which is then executed by the cruxVM.

.crux
Lexer
Parser
Emitter
.cxir

Key Features

  • Declarative — Define what your world contains, not how to build it
  • Type-safe — Catch errors at compile time
  • Readable — Clean syntax inspired by modern languages
  • Complete — Express any cruxIR structure

Example World

Here's a complete cruxLang world definition:

park.crux
world CloudPark {
  seed: 12345
  tick_rate: 1
  version: "1.0.0"
  description: "A peaceful park"

  // Define a zone
  zone park: area {
    x: 0, y: 0
    width: 100, height: 100
    terrain: "grass"
  }

  // Define an agent
  agent alice: visitor {
    position: { x: 10, y: 10 }
    energy: 100
    mood: "happy"
    tags: ["tourist"]
  }

  // Define behavior rules
  rule wander {
    priority: 1
    select: { type: "visitor" }
    when energy > 20
    do wander(speed: 2)
  }

  rule rest {
    priority: 2
    select: { type: "visitor" }
    when energy <= 20
    do rest(recovery: 5)
  }
}

Compilation

Compile cruxLang files using the CLI:

Terminal
# Compile to cruxIR
cruxos compile park.crux

# Output: park.cxir (JSON)

Or use the compiler programmatically:

TypeScript
import { compile } from '@cruxos/lang';

const result = compile(source);
if (result.success) {
  console.log(result.ir);
} else {
  console.error(result.errors);
}

Next Steps