Live data from Hacker News

Compiler Design in C

holub.com

31–40 of 46 posts

Re: Compiler Design in C

#31
post #15

Earlier quoted context omitted.

http://frama-c.com/

I think what flatestcat wants is something that actually functions and is proven to function correctly. Frama-C is yet another open source project that is long on hype but woefully short on delivery of actual, working code.

Replying to oneself using a bunch of different accounts is an abuse of this site.

Re: Compiler Design in C

#32
post #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 wi…

Speaking of SSA and optimizations, I just remembered that Andy Wingo (core contributor to Guile scheme) has a treasure trove of great articles, e.g. a fun intro to SSA [1] or CPS as used in Guile [2]. His blog is totally worth just browsing around.

[1] http://wingolog.org/archives/2011/07/12/static-single-assign...

[2] http://wingolog.org/archives/2014/01/12/a-continuation-passi...

Re: Compiler Design in C

#33
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.

If you want to have fun exploring how compilers work, in your spare time after a hard day working in C++, what better way than to reimplement a language you know?

On the other hand, my projects in this vein are C++ projects but they implement functional languages or Scheme. I have implemented one parser that creates a syntax tree from a simple equational language, and several interpretive backends, such as SKI-combinator-based graph reduction and a TIM-based interpreter. I do care about the speed of the compilers I use for production code, but not for this work. The Scheme compiler I wrote was written to run on my own Scheme interpreter which was written in C++.

The reason I think most hobby compilers I know of don't go the way I've gone is that it takes tons and tons of research to find out how functional languages are implemented, and the Appel books are a bit daunting, too.

Re: Compiler Design in C

#35

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

"...for all the claims it makes in the preface about being practical instead of theoretical..."

It's important to view this book in the context of its time. At that time, there were no books that showed you both the theory and complete running code for even this much. The compiler books (Dragon, 1st ed.; etc.) showed toy snippets but not a full lexer, parser, and code generator. There were only the articles in Dr. Dobb's about Small-C to show the way. So, at the time, Holub's book was a godsend. It married theory and implementation in a way that simply had not been done before. Hanson's and Fraser's 1995 book on a retargetable C compiler was a similar milestone, although it came out several years later.

After those two landmark books, explanations of full compiler implementations were no longer a rarity.

Re: Compiler Design in C

#36
post #16
post #9

why use c? its a horrific, logically incongruent lang

Maybe for fun? To learn something?

It was 1990. There were not many options. The standard language for technical books then was Pascal. C was a huge improvement over it. In addition, Holub was the C columnist for Dr. Dobb's.

Re: Compiler Design in C

#37
post #9

why use c? its a horrific, logically incongruent lang

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.

> 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

What exactly is "algebraic rectification"?

While it is generally true that having a formal semantics aids greatly in analysis, it is worth noting that a very large amount of program analysis work is targetted towards C. (And mind you, flexible, high level languages bring with it their own troubles. Analysis in the presence of higher order functions is not a panacea at all)

Re: Compiler Design in C

#38
I think that these days, if you're writing a compiler, it would be better done in one of * c++ to leverage llvm (afaik c++ is the best way to do that) and lots of existing code * some sort of ml, because ml is really good for lots of the things compilers need to do * self-host, because the compiler may be the best large-program workout your fledgeling language is going to get

Re: Compiler Design in C

#39
post #22

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

Interesting that on page 6 of this book, it talks about the same idea as LLVM (as I understand it):

"There are advantages and disadvantages to an intermediate-language approach to compiler writing[...] Intermediate languages give you flexibility as well. A single lexical-analyzer/parser front end can be used to generate code for several different machines by providing different back ends that translate a common intermediate language to a machine-specific assembly language. Conversely, you can write several front ends that parse several different high-level languages, but which all output the same intermediate language. This way, compilers for several languages can share a single optimizer and back end."

Re: Compiler Design in C

#40
post #27

Earlier quoted context omitted.

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++.

his point is still valid though
Post reply on HN