Live data from Hacker News

Want to write a compiler? Just read these two papers (2008)

prog21.dadgum.com

81–90 of 173 posts

Re: Want to write a compiler? Just read these two papers (2008)

#81
post #22

*Donald Knute -> Donald Ervin Knuth is the author of the book "The Art of Computer Programming" (in progress for a couple of decades, currently volume 4c is being written). It is quite advanced, and it will likely not cover compilers anymore (Addison-Wesley had commissioned a compiler book from Knuth when he was a doctoral candidate, now he is retired and has stated his goal for the series has changed). I disagree wi…

The "Dragon Book" is big on parsing but I wouldn't recommend it if you want to make many optimisation passes or a back-end. The first edition was my first CS textbook, back in the '90s and as a young programmer I learned a lot from it. A couple years ago, I started on a modern compiler back-end however, and found that I needed to update my knowledge with quite a lot. The 2nd ed covers data-flow analysis, which is ver…

Parsing is the front end to a compiler. Can't get semantics without first recognizing syntax. I have a hard time thinking about programming languages without seeing them as a parsing exercise first, every time.

Re: Want to write a compiler? Just read these two papers (2008)

#83
post #22

*Donald Knute -> Donald Ervin Knuth is the author of the book "The Art of Computer Programming" (in progress for a couple of decades, currently volume 4c is being written). It is quite advanced, and it will likely not cover compilers anymore (Addison-Wesley had commissioned a compiler book from Knuth when he was a doctoral candidate, now he is retired and has stated his goal for the series has changed). I disagree wi…

The dragon book almost convinced me never to try to write a compiler. I don't know why people recommend it. I guess you're a lot smarter than I am. There are some excellent books out there. In its own way, the dragon book is excellent, but it is a terrible starting place. Here are a bunch of references from the same vintage as OP. I recommend starting with a book that actually walks through the process of building a…

When I was professionally writing a compiler professionally (see https://ciex-software.com/intro-to-compilers.html) the Dragon book was the second book that I read. I found it very helpful. That was the first Dragon book. I got the second one later. I would have been ok to start with the Dragon book--the Compiler Generator book was a harder study.

Re: Want to write a compiler? Just read these two papers (2008)

#84
post #22

*Donald Knute -> Donald Ervin Knuth is the author of the book "The Art of Computer Programming" (in progress for a couple of decades, currently volume 4c is being written). It is quite advanced, and it will likely not cover compilers anymore (Addison-Wesley had commissioned a compiler book from Knuth when he was a doctoral candidate, now he is retired and has stated his goal for the series has changed). I disagree wi…

> "Compilers" by Niklaus Wirth This one? https://people.inf.ethz.ch/wirth/CompilerConstruction/Compil...

i found the same file but that's only 44 pages long ?

This ( https://github.com/tpn/pdfs/blob/master/Compiler%20Construct... ) seems to be a previous version (2005) and it's 131 pages long

Re: Want to write a compiler? Just read these two papers (2008)

#85
post #52

One nice piece of advice that I received is that books are like RAMs, you do not have to go through them sequentially, but can do random access to the parts of it you need. With this in mind I find it doable to get one the thick books and only read the part that I need for my task. But, to also be fair, the above random access method does not work when you don't know what you don't know. So I understand why having a…

A significant fraction of my technical library is used just this way--as a reference, checking out the parts to answer a specific question.

Re: Want to write a compiler? Just read these two papers (2008)

#86
post #30

Been working on a toy compiler for fun recently. I have ignored all the stuff about parsing theory, parser generators, custom DSL's, formal grammers etc. and instead have just been using the wonderful Megaparsec parser combinator library. I can easily follow the parsing logic, it's unambiguous (only one successful parse is possible, even if it might not be what you intended), it's easy to compose and re-use parser fu…

It seems to me LL and LR parser generators are overrated, and hand-written recursive descent is best in practice. I understand why academics teach them, but not why some spend so long on different parsing techniques, nor why hobbyists who just want to compile their toy language are directed to them. I work in PL, and from my first compiler to today, have always found recursive descent easiest, most effective (less bu…

> It seems to me LL and LR parser generators are overrated, and hand-written recursive descent is best in practice

I would now agree with that. My compiler experience was on a team that happened to have a LALR expert, Jeanne Musinski PhD, a student of Jeffrey Ullman. She invented a better error recovery for the language. Recursive descent would have been perfectly suited to the task.

> LR being more expressive than LL has never mattered.

Quite agree. One might guess that a language that needs that might be hard to program in.

Re: Want to write a compiler? Just read these two papers (2008)

#88

It's been about 4 years since I took a compilers course (from OMSCS, graduate program) and still shutter ... it was, hands down, the most difficult (yet rewarding) classes I've taken.

I used to judge CS programs based on if they had compiler classes or not.

Re: Want to write a compiler? Just read these two papers (2008)

#89
post #68
post #20

Earlier quoted context omitted.

10 years ago I took few coursera courses to fill the gaps in my computer science education. One of them was a compilers course done by karpathy. It was pure joy and a great learning experience. Also in my experience the joy of doing a course was much stronger correlated with the teacher's qualities rather than the subject itself.

Do you have a link by by chance? A quick search didn't turn anything up.

No, I am checking my emails (it was in 2012), and all the links are broken.

however I could dig out the references to it. Apparently it was a course by Prof. Alex Aiken and karpathy was a TA.

This repository seems to be a future version of the same course. https://github.com/gboduljak/stanford-compilers-coursework

Edit: found the videos from the course on the archive https://archive.org/details/academictorrents_e31e54905c7b266...

Re: Want to write a compiler? Just read these two papers (2008)

#90
I might be in the minority, but I think the best way to learn how to write a compiler is to try writing one without books or tutorials. Keep it very small in scope at first, small enough that you can scrap the entire implementation and rewrite in an afternoon or less.
Post reply on HN