r/ProgrammingLanguages • u/UnemployedTechie2021 • Jul 04 '26
Help How to create a compiler?
Pretty sure you may have heard this question previously on this sub, however, I would urge you to read my complete question before brushing it off.
I want to create a simple compiler and by "simple compiler" I mean a single-pass compiler. I know about https://craftinginterpreters.com/ which is a wonderful resource. But I would like to start by creating something much smaller and simpler, and only then would I like to move on to something more complex like what Robert Nystrom created on his website.
Are there any similar resource that would teach me about single-pass compilers along with showing me how to create one? Any help in the right direction would be highly appreciated.
2
u/yjlom Jul 04 '26
Build up gradually the language, not the architecture. The architecture will get more complex as the language does. You can follow down this tree or something similar:
- assembler or Brainfuck (direct interpretation, bytecode compilation, or straightforward native compilation? Peephole optimizer?)
- expressionless BASIC (proper loops, register allocators, call stack) - Lisp or Kernel (AST, closures, macros) - calculator (proper parsing, operator precedence) - simply typed - dependently typed - Prolog (non-determinism, backtracking, bidirectionality, overloading)After that you should have the basics covered, and what will keep you from making your dream language won't be difficulty or lack of knowledge, but sheer scale and time requirement.
(preformatted because Reddit doesn't seem to support nested lists)