No description
  • TypeScript 100%
Find a file
Lyssieth fd7ddb3bfe
refactor: restructured interpreter prompt to resolve unknown functions
- Updated system prompt in interpreter.ts to improve function resolution for unknown functions.
2026-06-02 08:17:53 +03:00
examples demonstrate "assertions" 2026-05-10 22:36:33 +03:00
src refactor: restructured interpreter prompt to resolve unknown functions 2026-06-02 08:17:53 +03:00
package.json first pass impl 2026-05-10 21:03:41 +03:00
README.md Update README.md 2026-05-10 20:25:15 +00:00

chaoslang

An interpreted programming language where every function call is evaluated by an LLM.

Web Version

It's usable on the web at https://lyssieth.wisp.place/chaos Bring your own LLM. The code is purely local (other than pulling in codemirror)

How it works

  • Control flow (if/while/return) and variable assignment are handled by the interpreter.
  • Every function call is sent to an OpenAI-compatible LLM for evaluation.
  • Functions do not need to be defined. Calling foo(a, b) or x.bar() will ask the LLM what that means.
  • print(...) is the only built-in function.

Syntax

// Assignment
x = 5;

// Function calls (LLM-evaluated)
y = add(x, 10);
z = "hello".uppercase();

// Control flow
if (gt(y, 10)) {
    print("y is greater than 10");
} else {
    print("y is not greater than 10");
}

while (gt(i, 0)) {
    print(i);
    i = sub(i, 1);
}

// Return (exits script early)
return y;

Literals

  • Numbers: 42, 3.14
  • Strings: "hello"
  • Booleans: true, false
  • Null: null
  • Arrays: [1, 2, 3]
  • Objects: {"name": "chaoslang", "version": 1}

Operators

There are no infix operators. Use function calls:

sum = add(a, b);
product = multiply(a, b);

Running

export OPENAI_API_KEY=sk-...
export OPENAI_MODEL=gpt-4o-mini        # optional
export OPENAI_BASE_URL=...             # optional, for non-OpenAI providers

bun run src/index.ts <file.chaos>

Debug mode

Set CHAOSLANG_DEBUG=1 to have the LLM include a reasoning note with each response:

CHAOSLANG_DEBUG=1 bun run src/index.ts script.chaos

Notes are printed to stderr:

[debug] add(5, 10) => 15 | note: The add function is assumed to perform addition on its arguments.

Project structure

src/
  lexer.ts       — Tokenizer
  parser.ts      — Recursive descent parser
  ast.ts         — AST node types
  interpreter.ts — Interpreter + LLM integration
  index.ts       — CLI entry point
examples/
  test.chaos     — Basic demo
  edge.chaos     — Edge cases (empty literals, return)