Live data from Hacker News

How I wrote a self-hosting C compiler in 40 days

sigbus.info

51–60 of 128 posts

Re: How I wrote a self-hosting C compiler in 40 days

#51
post #25
post #20

Now repeat for C++.

Considering that a considerably large subset of C is valid C++, it should be easy to modify 8cc to be valid C++ (e.g. by replacing implicit void*-casts to explicit ones), and then you already have a "self-hosting C++ compiler", but that could be considered cheating by some...

Except it won't compile anything but "C++" htat's really C code.

Re: How I wrote a self-hosting C compiler in 40 days

#52

Earlier quoted context omitted.

Please could you recommend an alternative?

Modern Compiler Implementation in C

By A. Appel? I heard that the ML version is better since much of the code apparently isn't very idiomatic (It was supposedly translated directly from the ML book). I would probably recommend both that and The Dragon Book, as they cover roughly the same material but in a slightly different manner.

Re: How I wrote a self-hosting C compiler in 40 days

#53
Self-hosting is pointless. Go has it--who cares. I wrote a program 1000x faster than the ruby one (at work) with zero bugs in Go, but I still don't want to use it(Go). Java is fine. Do I care if Java is self-hosting? No. I'll do (another) language in Javacc (my first one is still awesome) or ANTLR.

Re: How I wrote a self-hosting C compiler in 40 days

#54
post #30

For anyone interested in compiler writing and looking for a good resource to start, probably one of the best is the "Dragon Book": http://www.amazon.com/Compilers-Principles-Techniques-Tools-... I highly recommend it, but it's heavy stuff. There are probably simpler guides out there that just cover the basics.

Please stop recommending the Dragon Book already. It is not just heavy, it is mostly outdated and irrelevant.

Since technologies changes before the book is out, how does that hold in compiler domain? Are there any modern compiler book that explains around llvm/gcc as an example compiler?

Re: How I wrote a self-hosting C compiler in 40 days

#57
post #37
post #30

Earlier quoted context omitted.

Please stop recommending the Dragon Book already. It is not just heavy, it is mostly outdated and irrelevant.

It's fairly heavy in lexing and parsing theory, especially around finite automata, pushdown automata, etc. It's the kind of book you might want to read if you're reimplementing yacc. Modern code generation has moved on a bit, so I wouldn't dig too deeply into the latter third or so of the book. All in all, for a hobby compiler, it would be a poor choice; heavy on unnecessary theory in the front end and outdated on on…

It does not make any sense to reimplement yacc in the 21st century. There are far more powerful and yet simple parsing techniques, rendering all that automata stuff useless and outdated. Take a look at PEG, Pratt parsing and GLR.

Re: How I wrote a self-hosting C compiler in 40 days

#58

For anyone interested in compiler writing and looking for a good resource to start, probably one of the best is the "Dragon Book": http://www.amazon.com/Compilers-Principles-Techniques-Tools-... I highly recommend it, but it's heavy stuff. There are probably simpler guides out there that just cover the basics.

I am working my way through Alex Aiken's Coursera compiler course, almost 3/4th done and really liking it till now. There was another resource posted on HN earlier which takes you through building a compiler for lisp using C. http://www.buildyourownlisp.com/contents

Re: How I wrote a self-hosting C compiler in 40 days

#59
post #30

Earlier quoted context omitted.

Please stop recommending the Dragon Book already. It is not just heavy, it is mostly outdated and irrelevant.

Since technologies changes before the book is out, how does that hold in compiler domain? Are there any modern compiler book that explains around llvm/gcc as an example compiler?

Not sure if there are any books around LLVM or gcc, but there is a lot of up to date texts.

Grune at al., "Modern Compiler Design",

Appel, "Modern Compiler Implementation in ML",

and many more.

P.S. Because of a slow-ban, adding another one to this answer. This is the best source on SSA:

http://www.cri.ensmp.fr/people/pop/papers/2006-12-thesis.pdf

Post reply on HN