Live data from Hacker News

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

prog21.dadgum.com

91–100 of 173 posts

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

#91

Earlier quoted context omitted.

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.

The recommended advice is to start with semantics first. Syntax will change, there is not much point fixing it down too early.

Most of the work is actually the backend, and people sort of illusion themselves into "creating a language" just because they have an AST.

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

#92

Earlier quoted context omitted.

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.

Getting an overview of parsing theory is mainly useful to avoid making ambiguous or otherwise hard to parse grammars. Usually one can't go too wrong with a hand-written recursive descent parser, and most general-purpose language are so complicated that parser generator can't really handle them. Anyway the really interesting parts of compiling happen in the backend.

Another alternative is basing the language on S-expressions, for which a parser is extremely simple to write.

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

#93
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…

I'd never seen Knuth's middle name until your comment. I think it safely could be left out of an article.

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

#94
https://t3x.org has literal books on that, from a simple C compiler to Scheme (you might heard of s9) and T3X0 itself which can run under Unix, Windows, DOS, CP/M and whatnot.

PD: Klong's intro to statisticks, even if the compiler looks like a joke, it isn't. It can be damn useful. Far easier than Excel. And it comes with a command to output a PS file with your chart being embedded.

https://t3x.org/klong/

Intro to statistics with Klong

https://t3x.org/klong/klong-intro.txt.html

https://t3x.org/klong/klong-ref.txt.html

On S9, well, it has Unix, Curses, sockets and so on support with an easy API. So it's damn easy to write something if you know Scheme/Ncurses and try stuff in seconds. You can complete the "Concrete Abstractions" book with it, and just adapt the graphic functions to create the (frame) one for SICP (and a few more).

And as we are doing compilers... with SICP you create from some simulator to some Scheme interpreter in itself.

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

#95

These days there's an even easier way to learn to write a compiler. Just ask Claude to write a simple compiler. Here's a simple C compiler (under 1500 lines) written by Claude: https://github.com/Rajeev-K/c-compiler It can compile and run C programs for sorting and searching. The code is very readable and very easy to understand.

I did not and will not run this on my computer but it looks like while loops are totally broken; note how poor the test coverage is. This is just my quick skimming of the code. Maybe it works perfectly and I am dumber than a computer.

Regardless, it is incredibly reckless to ask Claude to generate assembly if you don't understand assembly, and it's irresponsible to recommend this as advice for newbies. They will not be able to scan the source code for red flags like us pros. Nor will they think "this C compiler is totally untrustworthy, I should test it on a VM."

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

#96
post #84

Earlier quoted context omitted.

> "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

You'll want part 2 as well for a total of 107 pages.

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

#98
post #89
post #68

Earlier quoted context omitted.

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_e31e5…

Ah yes, I remember this one. Very challenging indeed. Thanks!

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

#99

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 loved that course so much but it was incredibly difficult to do while also working

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

#100
What taught me how to write a compiler was the BYTE magazine 1978-08 .. 09 issues which had a listing for a Tiny Pascal compiler. Reading the listing was magical.

What taught me how to write an optimizer was a Stanford summer course taught by Ullman and Hennessy.

The code generator was my own concoction, and is apparently quite unlike any other one out there!

I have the Dragon Book, but have never actually read it. So sue me.

Post reply on HN