by shoggouth on 8/12/24, 6:26 PM with 156 comments
by signaru on 8/15/24, 1:11 PM
Nevertheless, I think I'm learning more from this book than most other books I've tried before that are far more theoretical or abstract. I'm still eager to reach the chapter on implementing C types. I think it's a good book, but it requires more effort than something like Crafting Interpreters or Writing a Compiler/Interpreter in Go, while also covering topics not in those books.
by synack on 8/15/24, 2:24 PM
It feels like a more advanced version of Crafting Interpreters.
I haven’t looked at the OCaml implementation at all. The text and unit tests are all you need.
Discussion on the Ada Forum: https://forum.ada-lang.io/t/writing-a-c-compiler/1024
by francogt on 8/15/24, 5:47 PM
by WalterBright on 8/15/24, 6:03 PM
https://archive.org/details/byte-magazine-1978-09 (part 1)
All 3 parts of Tiny Pascal:
https://albillo.hpcalc.org/publications/Easter%20Egg%20-%20T...
by hasbot on 8/15/24, 12:29 PM
by jerjerjer on 8/15/24, 5:34 PM
On topic, though: wouldn't a simpler language (maybe even a pseudo language) be a better target for a first learning compiler. I understand they don't build a full C compiler, but still. It looks to me like there's a lot of complexity add from choosing such a lofty target.
by fuhsnn on 8/15/24, 2:29 PM
by carom on 8/15/24, 11:23 PM
by the_panopticon on 8/15/24, 3:18 PM
by Coolbeanstoo on 8/15/24, 10:42 AM
by shoggouth on 8/12/24, 6:35 PM
https://www.amazon.com/Writing-Compiler-Programming-Language...
by sergius on 8/15/24, 12:38 PM
https://onlinebooks.library.upenn.edu/webbin/book/lookupid?k...
by tzs on 8/16/24, 2:49 PM
That last book was Allen Holub's "Compiler Design in C", which is from 1990. Here's how the blurb on the back describes it:
> Allen I. Holub's Compiler Design in C offers a comprehensive, new approach to compilers that proves to be more accessible to computer science students than the other strictly mathematical books.
> With this method in mind, the book features three major aspects:
> (1) The author develops fully functional versions of lex and yacc (tools available in the UNIX® operating system to write compilers), (2) he uses lex and yacc to develop a complete C compiler that includes parts of C that are normally left out of compiler design books (eg., the complete C "type" system, and structures), and (3) the version of yacc developed here improves on the UNIX version of yacc in two ways (error recovery and the parser, which automatically produces a window-oriented debugging environment in which the parse and value stacks are visible).
It's out of print, but the author has made a searchable PDF available on his website [1]. I found it quite useful.
Holub seems to like the "learn by doing" approach. He's got another book, "Holub on Patterns" that teaches all the design patterns from the gang of four book organically by developing two programs that together use all of those patterns. The two programs are an embedded SQL interpreter and a GUI application for Conway's Game of Life.
PS: Ooh. It occurred to me that No Starch Press books are often available on O'Reilly Learning. I checked and this one is there. So I guess it is going on my "don't need but am doing out of curiosity" pile after all.
by whartung on 8/16/24, 2:09 AM
Several "compiler light" style articles and books kind of walk over that part, and it can be non-trivial to do properly, especially with modern expectations.
I remember way back in the day, one of the early C compilers for the PDP, and, honestly, it could almost be argued that ed(1) had better error messages than what that thing produced.
A lot of simple compilers hit an error and just give up.
So, just curious what the approach was in this book.
by badsectoracula on 8/15/24, 12:34 PM
[0] actually from the readme in the github repo[1] it seems to be a C subset, not all of C
by quibono on 8/15/24, 10:22 AM
by sunday_serif on 8/15/24, 2:34 PM
Each chapter of the book includes a test suite to run against the code you’ve written.
In some ways, the tests in this book feel very similar to the labs in the book Computer Systems: A programmers perspective — which is high praise!
by alok-g on 8/15/24, 1:06 PM
Alternatively, I would like to learn about not just how to make a compiler, but also simultaneously a debugger, hot-reloading, etc.
by sim7c00 on 8/15/24, 4:48 PM
by i_don_t_know on 8/15/24, 11:07 AM
by sylware on 8/15/24, 2:38 PM
by viraj_shah on 8/15/24, 4:17 PM
https://www.linuxfromscratch.org/
"Linux From Scratch (LFS) is a project that provides you with step-by-step instructions for building your own custom Linux system, entirely from source code."