3 ms·
Always nice to see compiler tutorials that extend beyond the common "compile a calculator to a stack machine" genre. I've recently restarted writing a compiler
by hardwaregeek 4y ago
Always nice to see compiler tutorials that extend beyond the common "compile a calculator to a stack machine" genre.
I've recently restarted writing a compiler for fun and I've found that the hardest part is actually psychological. There's so much stuff I want to put into the compiler and language, so I often end up a little overwhelmed. When that happens it's important to just focus on the code and get something done.
It's also very easy to get myself into a rabbit hole, i.e. I'm using tree-sitter as my parser, but tree-sitter isn't designed to be used as a compiler front end, but hmm what if it was, maybe I should write something that automatically translates tree-sitter grammars to Rust AST definitions so that I don't have to manually convert a tree-sitter CST to an AST? Sure, I could go down that path, or I could bite the bullet and manually convert the tree.
Compilers are great exercises in scoping and prioritization because there's so damn many of these rabbit holes.
- prezjordan 4y agoIf someone were looking for an entry in the "compile a calculator to a stack machine" genre, what would you recommend?
- mgomez 4y agoChapters 14 and 15 from Crafting Interpreters[1] should be a good start. The entire book is worth a read if you decide to move beyond calculators. [1] https://craftinginterpreters.com/a-bytecode-virtual-machine.html https://craftinginterpreters.com/a-bytecode-virtual-machine....