r/Compilers • u/FairBandicoot8721 • May 02 '26
How long does it take to make a compiler?
Currently I am reading the "Engineering a compiler" book, I also made a working interpreter (not complete yet) and I will have 3 months of free time during the summer, so I decided to spend at least 5 hours working on my own compiler(those 5 hours include learning theory and coding the compiler). I plan to make my IR, optimze it a little and then compile to x86 assembly. Is this achievable or am I getting too ahead of myself? Thanks in advance!
49
Upvotes
39
u/Zenimax322 May 02 '26
I’ve been making mine for about 1.5 years. I compile to x86 assembly on windows, have a rudimentary gc and run about 2k unit tests. TBH it’s been the most rewarding/satisfying side project ive ever done. Ive learnt so many parts of the stack that I only had vague ideas about before. Definitely go for it!
3
u/Lord_Mystic12 May 03 '26
Depends on how many people are working on it , the complexity of it and the feature set. If you're just learning, should be a few months to a year. If you're trying to make a production ready compiler that you want the world to use with new features, atleast 2 years for your version one . And then you have to maintain it for years to come .
The one I'm working on is being done by 2 people rn , and it's been since 2024. We finished a stage zero, as in a prototype language that we use to rewrite the language.
2
u/Falcon731 May 03 '26
The way to approach a hobby compiler is to work vertically first, then broaden it.
So have an idea of where you want to finally get to in the back of your mind, but don't be distracted by it. Work in tiny steps.
The way I did it is to start with a tiny testcase
Initially work on doing just enough at each stage, so I have a compiler that can produce an executable to print 42. Ie get basic lexing, then a parser than understands int literals, function declarations and calls, build an AST, type check it (at this stage just check that the number of args matches number of parameters), produce some sort of IR, Map it to assembly (at this stage keep everything on the stack), write a small standard library (in my case in assembler) to link it with (to define printInt), assemble, link, execute.
That probably takes 1-2 weeks.
Don't get side tracked into optimisation, or fancy type checking, or anything else until you have something working for every stage on the pipeline.
Then gradually add features one by one. So probably the next step is to extend your compiler to be able to handle
Then
And so on. Gradually add things like control flow, arrays, etc. Each one goes through vertically. So add the concept of a while loop into the parser, then into code gen, and so on.
So you are always close to have a working compiler.
That way the project can scale as your time allows.
2
u/Only-Archer-2398 May 27 '26
Achievable but hard to say without details: dynamic types, static types, type checking, optimization (which ones), std/core library, functional programming, metaprogramming?
To me, with 3 months of hard work, you can get a nice toy, but not a gadget or a tool that you can use on a daily basis.
The real question is how your compiler will interact with the outside world: database, system, graphics, http and so on.
Finally, 3-4 years is an average
18
u/GayHomophobe1 May 02 '26
Just remember, even if you fail, you still get a learning experience back. I would 100% go for it. You're learning advanced string management, working in multiple layers of abstractions, and learning how the CPU runs instructions. Nothing there is bad to learn.
19
u/xmlhttplmfao May 02 '26
Depends on the complexity of the language and the maturity of the compiler. You could write a compiler for a simple language in a few weeks. For a language like C++, years, and years more to get all the optimizations correct. (assuming no use of llm coding tools).
19
u/StewedAngelSkins May 02 '26
How long is a rope?
6
u/ManyInterests May 02 '26 edited May 02 '26
If you've already made a working interpreter, a compiler is not really far off in terms of level of effort for a toy project. See: notes from Crafting Interpreters. The tokenization and parsing is 100% overlap anyhow. It's a 20mm shift to go from compiling bytecode for a VM/interpreter to compiling with LLVM or transpiling.
I have done David Beazley's week-long 'write a compiler' course three times. Twice in Python and once in Rust. 3 months is plenty of time with the right scope and guidance.
3
u/SadPlumx May 03 '26
I took a compiler construction class last year. We started with the lexer, then the parser, then the type checker, then there were some language specific stuff but with how little knowledge I had, it took me 20+ hours a week the entire semester.
2
u/Resident-Letter3485 May 03 '26
Years! But there are a lot of big milestones along the way that are very rewarding. If you are interested in a long time hobby project, it's hard to think of a better one than starting a compiler.
2
u/FirmSupermarket6933 May 03 '26
Don't forget that you also need to design the language, write standard library
2
u/Lucky_Trick_5703 May 03 '26
It’s achievable, but only if you keep the scope small. In ~3 months working a few hours a day, you can build a simple compiler: basic syntax, AST, a simple IR, and generate x86 for a subset of the language. That’s realistic.
What’s not realistic is a full language with complex parsing, strong type system, and serious optimizations. If you keep it minimal (expressions, control flow, maybe functions), you’ll learn a lot and probably finish. If you aim too big, you’ll likely get stuck halfway.
2
u/badcryptobitch May 03 '26
Depends on what your target is.
For us, a simple compiler and VM without any cryptography was quite fast. Around 3-4 months.
To actually integrate multiparty computation, it took at least 6+ months and we still aren't done.
Here's our compiler: https://github.com/Stoffel-Labs/Stoffel-Lang
Here's our VM: https://github.com/Stoffel-Labs/StoffelVM
For context, we are building a virtual machine for multiparty computation.
2
u/stumpychubbins May 05 '26
Unfortunately, the answer is "it depends". You could spend 10 years on it and not be finished. If all you care about is lexing+parsing+emitting functional assembly for a basic language then you can probably do it in a week, depending on prior knowledge.
2
u/mutzas May 08 '26
I would say between 6 months to 2-3 years depending on the finesse and scope you want.
4
u/umlcat May 02 '26
6-8 months ...
2
u/Ok_Chemistry_6387 May 03 '26
could be a weekend project if you use llvm. 3 months you could easily get something working. Will it be complete and robust etc? maybe not but it is more than possible.
1
u/trisxo91 May 04 '26 edited May 04 '26
How to convert to x86 just. Shade, I am Shadow 16x16. I stay on the silver surfer. One to u one unto me. 2 in the grandeur. just reverts back Tristan Stussy are watched eternally. He can slow even. Beer can't go wrong really. Trisxo91 one a day wine gets u a vegan doctorship degree. Im second on board. This. How to this padwan.
1
u/[deleted] May 03 '26
[removed] — view removed comment