5 ms·
Just what I love, a scientific and pedagogic CS article, in well formulated English. I would appreciate some introductory notes or links to prerequisites thoug
by dsco 9y ago
Just what I love, a scientific and pedagogic CS article, in well formulated English.
I would appreciate some introductory notes or links to prerequisites though. That would perhaps entice an audience who has no previous experience in writing compilers.
- giancarlostoro 9y agoI really want to be able to wrap my head around compilers but I'm not sure what a good "user friendly" resource is that wont stuff lots of fancy compiler buzzwords in my face and become white noise to me.
- shakna 9y agoLisp In Small Pieces would be my reccomendation. A relatively small book that takes you through writing 11 interpreters and 2 compilers.
- csl 9y agoIs it really that friendly when starting out, though? I found it brilliant, but quite the challenging read. I'd rather just read chapters four and five of SICP [1] and move on to Queinnec as a follow-up on more advanced topics. [1]: The book is free as well: https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html#%_toc_start https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html...
- shakna 9y agoTo be honest, I found LISP to be a lot easier than SICP, but that's probably just some learning styles stuff at play. SICP being freely available in both book form, and the lectures [0] makes it one of the best resources out there. (I just never found it's section on compilers that helpful. Again, probably learning styles.) [0] https://www.youtube.com/playlist?list=PLB63C06FAF154F047 https://www.youtube.com/playlist?list=PLB63C06FAF154F047
- csl 9y agoMaybe I need to reread LISP, then. I agree that SICP is laser-focused on Scheme, and thus leaves out general compilation techniques.
- Waterluvian 9y agoThis isn't about wrapping one's head around a compiler, but I thought you might find it useful. https://medium.freecodecamp.org/the-programming-language-pipeline-91d3f449c919 https://medium.freecodecamp.org/the-programming-language-pip... I enjoyed this read because it was a very user-friendly overview. After reading, I knew exactly what major pieces did what and therefore what to search for next on my own terms.
- weberc2 9y agoI'm writing my first compiler now, and it's been quite a learning curve. I've also realized how much nicer my language is for writing compilers than the language in which I'm implementing the compiler. That made me realize I could write the compiler in my language and then write an interpreter for my language which would only need to run once--to generate the compiler--after which point my compiler would be self-hosting. :p
- giancarlostoro 9y agoDo you mind sharing some of the resources you're using to learn? Book titles or URLs?
- weberc2 9y agoI haven't looked at any resources in particular. Basically my compiler has 3 parts--parser -> type checker -> code generation. Parsing was tricky at first, but then I stumbled upon a pattern which is pretty close to parser-combinators. Type checking seemed daunting, but my language happened to be Hindley-Milner compatible, and there's lots of reference information for HM. Code generation is easy in the base case, but I'm still wrapping my mind around template expansion.
- abecedarius 9y agoI wrote https://codewords.recurse.com/issues/seven/dragon-taming-with-tailbiter-a-bytecode-compiler https://codewords.recurse.com/issues/seven/dragon-taming-wit... about a tutorial-level compiler written in itself. Of course, a recommendation from someone who's learned from it instead of from the author would give a better signal. I also recommended the same Wirth book as lboasso, and a couple other books, down at the bottom of the page.
- lboasso 9y agoI would recommend "Compiler Construction" by Niklaus Wirth. This small book (< 200 pages) will teach you the basics and show you how to build a single-pass compiler for a subset of Oberon (a Pascal successor). The book is freely available here: http://people.inf.ethz.ch/wirth/CompilerConstruction/index.html http://people.inf.ethz.ch/wirth/CompilerConstruction/index.h... For a more comprehensive example, you can have a look at my compiler for the full Oberon language targeting the JVM. It is based on the principles of that book: https://github.com/lboasso/oberonc https://github.com/lboasso/oberonc
- i_don_t_know 9y agoI second the recommendation. Wirth's compiler book is a wonderful, concise and very readable introduction.
- ioddly 9y agoStart simple. If you haven't written an interpreter, do that first. Then figure out how to write a similar program that emits code for a virtual machine rather than evaluating the language. I'd keep an eye on http://www.craftinginterpreters.com/contents.html http://www.craftinginterpreters.com/contents.html, although it hasn't gotten to compilation yet (I think).
- tekknolagi 9y agoI'm actually trying to write an easy-to-digest compiler and companion reading series. It's for a compilers independent study class. You can track my progress here: https://github.com/tekknolagi/tigress https://github.com/tekknolagi/tigress At this point it's not well-documented, but the layers are numbered in order: l00, l01, l02... Each builds on top of the previous one. EDIT: I just added a mini evaluator for debugging purposes and so people can see what the language is like.
- userbinator 9y agothat wont stuff lots of fancy compiler buzzwords in my face and become white noise to me. Crenshaw's tutorial fits this perfectly: https://compilers.iecc.com/crenshaw/ https://compilers.iecc.com/crenshaw/ x86 version here: http://www.pp4s.co.uk/main/tu-trans-comp-jc-intro.html http://www.pp4s.co.uk/main/tu-trans-comp-jc-intro.html
- lboasso 9y agoI think Wirth's compiler book is more approachable for a beginner. Once you are done with that book you can also read "Project Oberon" from the same author. This way you can understand the implementation of a full graphical OS written from scratch for a custom made RISC processor implemented on a FPGA. The book and source code are available at: http://www-oldurls.inf.ethz.ch/personal/wirth/ProjectOberon/ http://www-oldurls.inf.ethz.ch/personal/wirth/ProjectOberon/
- sn9 9y agoStanford Lagunita has Stanford's Compilers course available for free, with the usual undergraduate prerequisites.