Examples
Ten programs, from a neural network forward pass to bare-metal LED blinkers. Seven run directly; the HTTP server keeps serving, the game needs SDL2, and the two blinkers produce assembly for their boards.
Neural Network Forward Pass
AI & MLneural_network.fdA 2-layer MLP (Multi-Layer Perceptron) in pure Fid, no external library. Input: 3 features, hidden: 4 neurons (ReLU), output: 2 neurons (Softmax). Uses the tensor and shape modules with runtime shape assertions.
$ fid run examples/neural_network.fdHTTP Server
Webhttp_server.fdA minimal HTTP server with route dispatch: GET / (hello world), GET /json (a JSON response) and POST /echo, using the http stdlib module. Serves on port 8080.
$ fid emit examples/http_server.fd -o http_server.exeMinimal Game
Gamesminimal_game.fdA full game vertical slice: open a window (SDL2), process keyboard + mouse input, update game state, render a frame (colored rectangles + sprite), play audio, and exit cleanly. Controls: WASD/arrows to move, Space for sound, ESC to quit.
$ fid ccompile examples/minimal_game.fd -o minimal_game # needs SDL2Mini Compiler
Systemsmini_compiler.fdA full lex → parse → codegen pipeline in one program. Demonstrates that Fid can express every pattern needed for a self-hosting compiler: tokenization, recursive descent, and code generation.
$ fid run examples/mini_compiler.fdJSON Parser
Datajson_parser.fdA JSON parser supporting arrays, objects, and escape sequences. Real-world parsing with recursive descent and Vec<T> for dynamic collections.
$ fid run examples/json_parser.fdLexer
Systemslexer.fdA tokenizer for arithmetic expressions. Character scanning, string building, and Vec<T>: the foundational patterns for any compiler.
$ fid run examples/lexer.fdParser
Systemsparser.fdA recursive-descent parser with a Box<T> AST. Demonstrates precedence climbing and tree construction: the same patterns the Fid compiler itself uses.
$ fid run examples/parser.fdCode Generator
Systemscodegen.fdAn x86-64 assembly text emitter. String concatenation and recursive traversal of an AST to produce assembly output.
$ fid run examples/codegen.fdRISC-V LED Blinker
Embeddedriscv_blink.fdBare-metal LED blink source for a SiFive HiFive1 Rev B (FE310 SoC, RISC-V). Uses asm!() for memory-mapped GPIO and a busy-wait delay, no stdlib, no OS. The native RISC-V output targets Linux, not bare boards, so an external assembler and flashing tools are needed to put this on the board.
$ fid codegen --target riscv examples/riscv_blink.fdRaspberry Pi LED Blinker
Embeddedrpi_led_blink.fdARM64 bare-metal LED blink source for a Raspberry Pi 3 (BCM2837). The native ARM64 output targets Linux, and the --bare emitter produces x86-64, not a deployable Pi image. An external ARM64 assembler and deployment tooling are still needed.
$ fid codegen examples/rpi_led_blink.fd --target arm64Self-host readiness
These examples prove Fid can build its own compiler
The compiler examples (lexer, parser, codegen, mini_compiler) demonstrate every pattern needed for self-hosting: tokenization, recursive descent, Box
Works everywhere: interpreter, C, and native emitters
- • Tokenization: character scanning, string building, Vec<T>
- • Parsing: recursive descent, precedence climbing, Box<T> AST
- • Code generation: string concatenation, recursive traversal
- • Full pipeline: lex → parse → eval → codegen in one program
- • Real-world parsing: JSON with arrays, objects, escapes
Verified against the real compilers
The neural network, JSON parser, lexer, parser, code generator and mini compiler printed the same output through fid emit as through the interpreter when checked on Nov 3, 2026 (before the Nov 4–6 compiler changes).
Run them yourself.
Install the toolchain and run any example with a single command. On Windows, native builds need no assembler, linker or C compiler.