No description
- TypeScript 100%
- Updated system prompt in interpreter.ts to improve function resolution for unknown functions. |
||
|---|---|---|
| examples | ||
| src | ||
| package.json | ||
| README.md | ||
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)orx.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)