Live data from Hacker News

Compiler Design in C

holub.com

21–30 of 46 posts

Re: Compiler Design in C

#21
post #9

why use c? its a horrific, logically incongruent lang

I won't echo this sentiment, but; why use C for writing a compiler? It seems that languages in the ML family, among others, are nicer for that kind of domain.

I guess it at least has its uses if you want your compiler to be really fast.

Re: Compiler Design in C

#23
post #8

Earlier quoted context omitted.

I agree, there were more interesting/amusing cover illustrations than the abstract, generic ones on the bulk of compiler and computing books today. That's how the Dragon Book got its name too. Related article: http://www.globalnerdy.com/2007/09/14/reimagining-programmin...

Speaking about covers, Forth Programmer's Handbook comes to mind :) http://www.amazon.com/Forth-Programmers-Handbook-3rd-Edition...

Check out this one: http://ecx.images-amazon.com/images/I/61wk1jiBkRL._SX258_BO1...

Re: Compiler Design in C

#24
post #22

Can somebody recommend a book that covers recent techniques implemented in LLVM?

Much of the frontend is pretty much the same: parsing, semantic analysis, type checking. LLLVM mostly comes into play when generating the code. Instead of generating assembbler or opcodes directly, you call into LLVM to create data structures that represent low-level code and then a final call to gen machine code or JIT.

There are several versions of the LLVM Kaleidoscope language tutorial where you build a compiler that supports numeric operations, it is often based on Pratt parsers (at least the official C++ version[1]), but there's a C version on github [2].

In my opinion, you could get pretty far by reading the "Compiler design in C" or "Modern compiler implementation in C" up to the point of optimization and then applying the code generation from kaleidoscope tutorials. LLVM takes care of many optimizations.

[1] http://llvm.org/docs/tutorial/LangImpl1.html [2] https://github.com/benbjohnson/llvm-c-kaleidoscope

Re: Compiler Design in C

#25
post #22

Can somebody recommend a book that covers recent techniques implemented in LLVM?

The good intro to compilers is Engineering a Compiler. It focuse more on optimization then most intro books, and its all SSA.

If you want to go all in on SSA optimization, there is a book called Static Single Assignment Book and its written by a hole list of compiler writers. Its not finished but there is still a lot of information.

You can find it here: http://ssabook.gforge.inria.fr/latest/book.pdf

Or you can go with the classic, Advanced Compiler Design & Implementation. See here, http://www.amazon.com/Advanced-Compiler-Design-Implementatio...

All of them will teach you a lot about LLVM.

Re: Compiler Design in C

#26
This book appears to be more of a "compiler-compiler design in C"; it goes through how to write a lexer and parser generator, then writes a compiler using them, and I think the resulting compiler is a bit of a letdown: it does not much more than translate C into a linearised subset of C, and so the IMHO more "interesting" and important parts of the back-end like register allocation and instruction selection are completely absent.

It's a good if somewhat outdated book if you're interested mostly in parsing and lexing, but for all the claims it makes in the preface about being practical instead of theoretical and all the source code presented throughout, I found the lack of actual Asm code generation (or any mentions of this compiler being able to compile itself) disappointing.

Parser/lexer generators also seem to have fallen out of favour for the creation of actual compilers, both big and small, at least for C-like languages; techniques based on recursive-descent (RD) are quite popular now.

On the "big, production-quality" side, gcc used a generated parser but moved to a handwritten RD-based one, and Clang always used RD. EDG's front-end, used in Intel's and other commercial compilers, is also handwritten RD. On the small "toy compiler"/hobbyist/experimentation side, there's TCC/OTCC, CC500 ( https://news.ycombinator.com/item?id=8576068 ), C4 ( https://news.ycombinator.com/item?id=8558822 ), SubC ( http://www.t3x.org/subc/ ), and many others, all based on RD parsers.

In fact I can't think of any C compilers at the moment that are using a generated parser/lexer...

Re: Compiler Design in C

#27

Earlier quoted context omitted.

I know what you mean, man. Lots of n00bz, ricers, and fanboiz will claim C is the fastest, most efficent lang because you can get "close to the metal" and "tweak". In reality, any code beyond trivial complexity will benefit much more greatly from algebraic rectification, which can only be done with certain languages that are amenable to formal analysis.

Until I see an award-winning 4k/64k demo written in one of these ultra-high-level languages, I stand by my opinion that C is more efficient.

Check your facts. A large majority of award-winning 4k/64k are written in C++.

Re: Compiler Design in C

#28
What real world experience does Allen Holub have with compiler design? As far as I can tell, he has not contributed to gcc, LLVM,or written any toy compilers like TCC.

Re: Compiler Design in C

#29
post #3

How I love these 90s style book covers, color palettes :)

I agree, there were more interesting/amusing cover illustrations than the abstract, generic ones on the bulk of compiler and computing books today. That's how the Dragon Book got its name too. Related article: http://www.globalnerdy.com/2007/09/14/reimagining-programmin...

Also the Dinosaur Book[1]. I don't think Silberschatz et al. could have pulled this off if they were starting today.

[1] http://galvin.info/2007/03/13/history-of-the-operating-syste...

Re: Compiler Design in C

#30
post #21
post #9

why use c? its a horrific, logically incongruent lang

I won't echo this sentiment, but; why use C for writing a compiler ? It seems that languages in the ML family, among others, are nicer for that kind of domain. I guess it at least has its uses if you want your compiler to be really fast.

The book was published in 1990. I worked on a commercial compiler in 1990, and many of our customers ran it under 16-bit MS-DOS.
Post reply on HN