This is what I once wrote to a reader:
- Nand2Tetris book - http://www.nand2tetris.org/
- The paper "An Incremental Approach to Compiler Construction", by Abdulaziz Ghuloum. You can find a hosted PDF version of the paper and an implementation of its contents here: https://github.com/namin/inc\
- Jack Crenshaw's classic "LET'S BUILD A COMPILER" from 1988. Even though it's kinda dated (he's using Turbo Pascal), it's one of the great "let's roll our sleeves up and write some code" texts. Here is the PDF version: http://compilers.iecc.com/crenshaw/tutorfinal.pdf
- Then there are also the 4th and 5th chapters of Structure an Interpretation of Computer Programs (SICP), in which you'll build an interpreter and a kinda bytecode-compiler for a virtual register machine. It's a pretty abstract and seemingly alien affair (using a Lisp dialect to build a virtual register machine for a bytecode defined in Lisp, produced by a Lisp compiler, etc.), but it teaches the concepts behind the whole compiler and VM thing. You can find the full text here: https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html#%_toc_start
Then I'd say diving into the source code is in order. I recommend starting with a small codebase. Here is a list of a few of my favorites:
- femtolisp - small Scheme implementation as a VM and bytecode compiler - https://github.com/JeffBezanson/femtolisp
- wren - Stack VM and bytecode compiler written in C - https://github.com/munificent/wren
- guile - a Scheme register VM and compiler - https://www.gnu.org/software/guile/ https://www.gnu.org/software/guile/manual/html_node/A-Virtual-Machine-for-Guile.html#A-Virtual-Machine-for-Guile https://www.gnu.org/software/guile/manual/html_node/Compiling-to-the-Virtual-Machine.html#Compiling-to-the-Virtual-Machine
- lua - be sure to check out the older versions, like 3.x and 1.x, too, because they are even simpler
- chicken scheme
- c4 - a C compiler in 4 functions: https://github.com/rswier/c4
- 8cc - a small, clean, readable C compiler - https://github.com/rui314/8cc - Here's the blog post by the author explaining the project: http://www.sigbus.info/how-i-wrote-a-self-hosting-c-compiler-in-40-days.html
More specific recommendations depend on what you want to do exactly: a compiler that outputs machine good, one that outputs C, one that outputs assembly and uses an assembler, or maybe even a JIT compiler?