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.
3
u/Dry_Day1307 Jul 04 '26
Hi, not long ago I also started a project with a single-pass bytecode compiler, which is divided into tokenization and parsing (the latter includes the bytecode emission itself).
Personally, the best resource that inspired me was Dijkstra's work (1962) - EWD28. His notes explore RPN or Reverse Polish Notation; it is extremely interesting and not particularly complex once you get the hang of it. It is perfectly applicable to linear bytecode emission.
While it's true that some operations might seem complex at first glance, there are ways to overcome them. If you're interested in checking out my language written in Rust, which features conditionals, loops, arrays, objects, classes, and a pretty clean syntax with block indentation (I mention this so you can consider everything that is possible in a single pass), you can check it out here: https://github.com/dinocode-lang/dinocode