Featured image of post Building a Compiler from Scratch with AI: Quad and Tri

Building a Compiler from Scratch with AI: Quad and Tri

Inspired by the rapid evolution of AI models in late 2025, I built the compilers "Quad" and "Tri" from scratch with AI, outputting native executables.

Note: The original text of this article was written on a smartphone, but when I asked Gemini to proofread it, the writing style was almost completely rewritten 😢 (The nuances of the original text should still remain…!)

Introduction

Seeing the rapid performance improvement of AI models (GPT-5.2 Codex, Gemini 3 Pro, Claude 4.5 Opus thinking, etc.) from around the end of 2025, I suddenly thought: “With current AI, can’t I write a compiler from scratch and get it to spit out a native exe?”

My own compiler implementation knowledge stops at Brainfuck. As a result, the coding was 100% left to AI (I didn’t write a single line), implemented about 10,000 lines in Rust, and completed a language where not only FizzBuzz but also dynamic arrays and structures work.

The deliverables are on GitHub. https://github.com/takoyakisoft/quad-tri/

Language Concept: Quad and Tri

With the concept of “improving visibility for humans while maintaining token efficiency for AI”, I designed the following two languages.

  • Quad: All keywords (reserved words) are unified to 4 characters
  • Tri: All keywords are unified to 3 characters

The compiler distinguishes them by extension.

Aiming for “Visibility for Humans” + “Token Efficiency”

The biggest concept is “aligning the vertical lines”. Because the length of reserved words is fixed, the start position of the statement naturally aligns vertically when writing code, making it very easy for humans to see.

Also, the adopted keywords are selected from common English words that can be reliably represented by 1 token including spaces. Like existing languages such as Python, it is not split by the tokenizer, so it maintains a good state of generation cost (token efficiency) for AI.

Sample Code

Quad (4-character binding) I chose 4-letter English words like func, cell (var), loop, back (return). Note that the vertical lines are neatly aligned.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
func main() -> int:
    cell i: int := 1
    loop i <= 20:
        when i % 15 == 0:
            println("FizzBuzz")
        elif i % 3 == 0:
            println("Fizz")
        elif i % 5 == 0:
            println("Buzz")
        else:
            println(i)
        i := i + 1
    back 0

Tri (3-character binding) def, var, for, ret (return), iff/elf/els, etc.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def main() -> int:
    var i: int := 1
    for i <= 20:
        iff i % 15 == 0:
            println("FizzBuzz")
        elf i % 3 == 0:
            println("Fizz")
        elf i % 5 == 0:
            println("Buzz")
        els:
            println(i)
        i := i + 1
    ret 0

Tech Stack and Adoption of Cranelift

I adopted Cranelift for the compiler backend.

  • Language: Rust
  • Backend: Cranelift
  • Dev Environment: Github Actions, Windows 11, Codex Web/Jules

Initially, I considered LLVM, but gave up because the setup for cross-platform and development environment (Windows/Web/CI) seemed too complicated. Cranelift is completed only with Rust crates (libraries) and can output native exe, so it was optimal for the purpose of “explosive development in 2 days”. It works quickly just by passing IR (Intermediate Representation).

Implemented Features

As a result of repeating wall-bouncing with AI (which is completely giving instructions), I was able to implement the following features.

  • Native exe output (Windows/Linux)
  • Variables, functions, loops, conditional branching
  • Dynamic arrays, structures
  • Receiver functions
  • Result / Option types
  • Memory allocation and deallocation (this is still buggy)

Honestly, I didn’t think a person who only knew Brainfuck could create a language with receiver functions and structures in 2 days. “Reinventing the wheel” has clear input and output, so it might be the task that AI is best at.

Difficulties and AI Evaluation

Only the notation for fixed-length arrays did not come up with a good idea even after discussing with AI, so it has become a slightly unique notation.

1
2
# [Size]Type - A Go-like writing style
var wds: [6]text := ["foo", "bar", ...]

Also, when I had the AI itself review the generated code, I received harsh comments such as “Error handling is sloppy” and “Reliability is low”. I feel the wall unique to AI coding that it works but is not production code.

Conclusion

The motive was “Let’s make a joke language”, but I was moved when the exe actually worked. Coding was 100% left to AI, but the fun of deciding concepts and specifications remains firmly on the human side. It was a weekend where I realized that in 2026, programming completely shifted from “writing” to “talking about specifications and generating”.

Built with Hugo
Theme Stack designed by Jimmy