The new [tomekw/stcc](https://github.com/tomekw/stcc) repository shows how a classic teaching compiler can be expressed entirely in Ada, offering a compact reference implementation that compiles Lisp‑style expressions to C‑like syntax and demonstrates how Ada’s strong typing and package system can be harnessed for language tooling.
Re‑creating the Super Tiny Compiler in Ada – A Minimalist Journey into Language Implementation

Thesis
The Super Tiny Compiler (STC) has become a staple teaching artifact for anyone learning how compilers work: a handful of files that parse a tiny Lisp‑style language and emit simple C‑like code. In the repository tomekw/stcc, Tomasz Wałkuski takes this pedagogical example and rewrites it in Ada, a language traditionally associated with safety‑critical systems rather than compiler construction. The project demonstrates that Ada’s expressive type system, modular packaging, and built‑in tooling can produce a clean, self‑contained compiler that is both readable and extensible, while staying faithful to the original STC’s spirit of minimalism.
Key Arguments
1. Ada as a Viable Host Language for Compilers
- Strong typing and contracts – Ada’s subtype and range constraints let the author encode token kinds, AST node variants, and error conditions directly in the type system. This reduces the need for runtime checks that are common in C‑style implementations.
- Package architecture – The code is split into logical units (
src/,tests/) and compiled with a GNAT project file (stcc.gpr). The project file declares dependencies, compiler switches, and test harnesses, providing a reproducible build environment without external build scripts. - Readability – Ada’s verbose syntax, while sometimes criticized for verbosity, makes the flow of the compiler explicit: tokenization, parsing, code generation, and the main driver are each a clearly named subprogram.
2. Faithful Re‑implementation of the Original STC Workflow
The original STC, popularized by the “Super Tiny Compiler” tutorial series, accepts an S‑expression like (add 2 (subtract 4 2)) and produces add(2, subtract(4, 2));. The Ada version mirrors this pipeline:
- Lexical analysis – A simple hand‑written scanner walks the input string, producing a stream of tokens (
ParenOpen,ParenClose,Identifier,Number). - Parsing – A recursive‑descent parser builds an abstract syntax tree (AST) where each node is a discriminated record (
type Expr (Kind : Expr_Kind) is record ... end record;). - Code generation – A visitor pattern walks the AST and emits the target C‑like syntax, handling function calls and numeric literals.
Running the compiled binary (./stcc) or invoking the same logic through the Tada task runner (tada run) yields the expected output, confirming functional parity with the original JavaScript/Python versions.
3. Integration with Modern Ada Tooling (Tada)
The repository ships a tada.toml configuration file, enabling the use of the Tada build‑automation framework. With a single command tada test, the suite of unit tests located in stcc_tests.gpr is executed, providing immediate feedback on regressions. This illustrates how contemporary Ada ecosystems can support rapid development cycles similar to those found in more mainstream scripting languages.
4. Minimal Dependency Footprint
All source files are handwritten; there are no external libraries beyond the Ada runtime. The README.md explicitly states that the codebase is “written by hand,” emphasizing the educational intent: readers can study every line without needing to understand a complex third‑party parser generator or code‑gen library.
Implications
- Educational value – By presenting the STC in Ada, the project opens a door for students of formal methods and safety‑critical software to see how language implementation concepts translate into a language that enforces correctness by design.
- Ada community visibility – Demonstrating a compiler written in Ada counters the perception that Ada is only for low‑level embedded or avionics code. It may encourage Ada developers to experiment with tooling, DSLs, or even full‑featured language front‑ends.
- Cross‑language portability – The same source can be compiled with GNAT on Linux, macOS, or Windows, and the generated binary behaves identically across platforms. This reinforces Ada’s reputation for write‑once, run‑anywhere semantics.
Counter‑Perspectives
- Verbosity vs. brevity – Critics may argue that the Ada implementation is longer than the original JavaScript or Python versions, potentially obscuring the core ideas for beginners who value conciseness. However, the trade‑off is intentional: the extra lines serve to illustrate Ada’s safety guarantees.
- Performance considerations – While the compiler is tiny, Ada’s runtime may introduce a larger binary footprint compared with a hand‑rolled C implementation. For a teaching tool this is negligible, but it could matter in constrained environments.
- Ecosystem maturity – The Ada community, though stable, lacks the breadth of package repositories found in npm or PyPI. New learners might need to set up GNAT and Tada, which can be a steeper initial hurdle than installing Node.js.
Conclusion
The tomekw/stcc repository stands as a concise yet fully functional demonstration that Ada can serve as a host language for compiler construction without sacrificing clarity or correctness. By adhering closely to the original Super Tiny Compiler’s workflow while leveraging Ada’s strong typing, modular packages, and modern tooling, the project offers a valuable resource for educators, students, and Ada enthusiasts alike. Whether you are looking to understand the mechanics of parsing and code generation, or you simply want to see Ada applied beyond its traditional domains, this tiny compiler provides a concrete, hands‑on example that bridges theory and practice.
Further Reading
- The original Super Tiny Compiler tutorial series – a gentle introduction to compiler phases.
- Ada’s official documentation on GNAT project files.
- The Tada framework for Ada build automation.

Comments
Please log in or register to join the discussion