Skip to content

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 & ML
neural_network.fd

A 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.fd
Open in Playground, run it in your browser
tensorshapematmulrelusoftmax

HTTP Server

Web
http_server.fd

A 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.exe
httprouting

Minimal Game

Games
minimal_game.fd

A 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 SDL2
sdlgameloopaudioinputrendering

Mini Compiler

Systems
mini_compiler.fd

A 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.fd
Open in Playground, run it in your browser
lexerparsercodegenBox<T>

JSON Parser

Data
json_parser.fd

A 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.fd
Open in Playground, run it in your browser
jsonparsingVec<T>

Lexer

Systems
lexer.fd

A tokenizer for arithmetic expressions. Character scanning, string building, and Vec<T>: the foundational patterns for any compiler.

$ fid run examples/lexer.fd
Open in Playground, run it in your browser
tokenizationVec<T>

Parser

Systems
parser.fd

A 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.fd
Open in Playground, run it in your browser
parsingBox<T>recursive descent

Code Generator

Systems
codegen.fd

An x86-64 assembly text emitter. String concatenation and recursive traversal of an AST to produce assembly output.

$ fid run examples/codegen.fd
Open in Playground, run it in your browser
codegenx86-64assembly

RISC-V LED Blinker

Embedded
riscv_blink.fd

Bare-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.fd
RISC-Vbare-metalasm!()GPIOembedded

Raspberry Pi LED Blinker

Embedded
rpi_led_blink.fd

ARM64 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 arm64
ARM64bare-metalasm!()GPIORaspberry Pi

Self-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, BoxASTs, and code generation. The interpreter and C codegen backends work for all of them.

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.