Read the whole thing
The scanner, compiler and VM are small enough to follow in one sitting. There is no parser generator and no hidden runtime.
A small language, built in C
Byte compiles source to bytecode in a single pass, then runs it on a small stack VM. The whole interpreter is 2,334 lines of C, and it runs in your browser through WebAssembly.
No install. No account. Code stays in your tab.
func fib(n) {
if n < 2 { return n }
return fib(n - 1) + fib(n - 2)
}
for i = 0; i < 5; i += 1 {
print fib(i)
}
0 1 1 2 3
Why Byte
Byte is not a syntax sketch with a fake backend. It scans, compiles and executes, and every stage is small enough to open and read.
The scanner, compiler and VM are small enough to follow in one sitting. There is no parser generator and no hidden runtime.
Functions, recursion, closures, strings and compound assignment. The surface is small, but the programs are real.
The interpreter builds to WebAssembly. The playground runs actual bytecode in a worker, with no server round trip.
One CMake flag turns on disassembly and a stack trace for every instruction. Errors report the line they came from.
The idea
The language
No package manager. No framework. Just the parts a language needs to run a program, plus closures to make them interesting.
func counter() {
let count = 0
func increment() {
count += 1
return count
}
return increment
}
let next = counter()
print next()
print next()
print next()
1 2 3
The pipeline
Three stages, one direction. Each stage is a file you can open and read.
The scanner turns characters into tokens and tracks line numbers. Comments and blank lines fall away.
A recursive descent parser handles statements. Pratt parsing handles expressions. Bytecode goes straight into a chunk, with no AST in between.
The stack VM walks the chunk one opcode at a time. Turn on trace mode to see the value stack after every instruction.
One pass, no AST. The compiler writes bytecode as it parses, and the VM executes that chunk on an expression stack. The whole path is source, tokens, bytecode and values.
Docs
Closures, Pratt parsing and the debug trace each have a short note that explains the mechanism and the tradeoffs.
Questions
The short answers. The docs have the long ones.
Read the language guideByte is a small programming language with a compiler and a stack virtual machine, both written in C. It started as a way to learn how languages work end to end, and it has grown into a complete little language.
No. Byte is an experimental language and a learning project. There is no package manager, no standard library beyond print and clock, and no stability promise. Use it to learn, teach or experiment, not for anything important.
Variables, arithmetic, strings, conditionals, loops, functions, recursion and closures. There are no arrays, maps, classes, modules or exceptions yet.
The interpreter is compiled to WebAssembly with Emscripten and runs inside a Web Worker in your browser. Each run starts from a clean VM, and a program that runs longer than five seconds is stopped.
No. The playground is a static site. Your source is passed to the WebAssembly module in your tab and is never uploaded. The site has no analytics and sets no cookies.
Yes. Clone the repository, configure it with CMake and build the byte executable. You need a C11 compiler. Emscripten is only needed for the browser build.
There is no stable embedding API yet, but the source is public and builds with CMake. web/byte_web.c shows the smallest integration point: reset the VM, pass a source string to byte_run and forward the output.
It is a compact, complete example of a compiler and a virtual machine. The goal is not to replace your favorite language. The goal is a codebase you can read in one sitting and change without fear.
Start with the language guide, then the architecture note. If closures or Pratt parsing are unfamiliar, those notes go deeper. The debugging note shows how to print disassembly and a stack trace.
The repository does not include a license file yet, so no reuse rights are granted by default. If you want to use the code, open an issue and ask.
Try it
The playground compiles your source to bytecode in the browser and stops runaway loops after five seconds.
No install. No account. Nothing leaves your tab.