dil icon indicating copy to clipboard operation
dil copied to clipboard

Document potential research sources

Open spy-t opened this issue 5 years ago • 1 comments

As stated in the README this is an educational project and although it is not intended to replace the relevant course or textbook I think it would be wise documenting potential sources for anyone interested in learning about compilers in general and specifically about helping with the project.

spy-t avatar Nov 26 '19 19:11 spy-t

Thanks mate, good one! And you just reminded me that I should make a new label. Here are some resources I like: Note: I don't like much theory and classical textbooks for front-end code (you might not know what front-end is - just skip this note, not so important). I really think that one will learn better by practicing and by reading code of an actual compiler. That said, I'm a big fan of theory when it comes to back-ends and especially optimization!

  • Nora Sandler's "Writing a C compiler series" Of course, you won't write a C compiler. :P You will write a small subset of it which is nonetheless interesting. It inspired my first compiler and using this subset one can implement first assignments in the course Introduction to Programming in UoA. What is more, it takes an incremental approach. That is, it adds one feature at a time, by teaching how to handle that feature in all parts of the compiler (lexer, parser, codegen). In other words, it doesn't do: First let's build the whole lexer, then the whole parser etc. That is good because first of all I think it's more educational and second, you can have an executable from your own compiler in an hour or 2 (it might only return 0 but hey, we all started somewhere).

  • Engineering a Compiler, 2nd Edition Truly a masterpiece. An incredible introduction to pretty much every topic (apart from lexing parsing that I don't really like). Anything from chapter 4 and on is amazing IMO. I don't think it's good to read it in one sitting but rather returning back to it from time to time.

  • Practical Compiler Construction Not really popular but I think it's a good one. The code has bad decisions in it but nonetheless, it shows you how to implement an interesting subset of C.

Moving to more real-world resources:

  • 9cc C compiler Actual C compiler with an educational point of view. I think it's a good starting point.

  • lacc C compiler Another actual C compiler with a custom IR. I like this one even more than 9cc I think. Both are great though!

  • Bitwise This dude is a mastermind of code architecture. It's almost funny how he has achieved simplicity + power of this compiler. If you have some familiarity with compilers (i.e. you have written a simple one), then this would definitely be my number 2 choice

  • lcc, A Retargetable Compiler for ANSI C A real world compiler along with a book explaining it => Gold. I don't think that the code is especially readable. Also, some of the choices that they make are not modern and difficult. Lastly, because it's C, you have to learn to handle all its weirdness. That's it for the negatives. On the positive side this a compiler that made some of the best architectural decisions ever. Don't forget that this compiler was not an educational project only. It was actually used by a lot of people. Probably a lot of modern compilers were inspired by it. Personally, I think it's a must read for any compiler writer.

  • V language compiler Again, IMO not some of the best decisions in the world. However, the compiler is real-world software, it's small and relatively digestible.

  • D programming language reference compiler I'll be honest here: This is not for the faint of heart. :) That said, this is a piece of engineering art, especially the front-end. I'd much rather read this compiler than a C++ giant compiler. You probably will learn much more things.

Please, to anyone that has any experiece with compilers, add your own favorite resources!

baziotis avatar Nov 26 '19 20:11 baziotis