Thought this was going to be an inspiration to me to continue with my pet project of writing my own little programming language. But it starts off on day 8 with him already having written a basic compiler, with no explanation of how he did any of the basics. Still interesting, just not what I thought it was.
I think the best inspiration to take here is that the best way to write a compiler in 40 days is to first write one in 400 days. From the first entry: > Implementing these features is easy because this is the second time for me.
How I wrote a self-hosting C compiler in 40 days
21–30 of 128 posts
Re: How I wrote a self-hosting C compiler in 40 days
#22>I should have written beautiful code from the beginning, but because I needed to learn by writing a working code, the rewriting was unavoidable.
>I should probably change my mind to implement all the features from end to end. I may find it fun as I'm approaching the goal. Sometimes, I have to write more code than I want to write in order to achieve a goal.
>In a tough situation like this, I probably should recall the fact that the compiler was just in one file, to see how much progress I've made in a month. It just reads an integer with scanf() and prints it out with printf(). Really, I made so much progress in one month. Yeah, I think I can do this.
Re: How I wrote a self-hosting C compiler in 40 days
#23Thought this was going to be an inspiration to me to continue with my pet project of writing my own little programming language. But it starts off on day 8 with him already having written a basic compiler, with no explanation of how he did any of the basics. Still interesting, just not what I thought it was.
Same here. I have been trying the same project as you... and get stuck on the grammar, every.single.time. Are you done with that part yet?
Re: How I wrote a self-hosting C compiler in 40 days
#24Re: How I wrote a self-hosting C compiler in 40 days
#25Now repeat for C++.
Re: How I wrote a self-hosting C compiler in 40 days
#26Long ago UNIX had compiler writing tools like yacc and lex. I wonder if they are useful for exercises like this.
Noting that though, for this specific exercise they're not as useful because the author intended for this compiler to be self-hosting. It would be hard to be self-hosting if the compiler have to be able to compile the C code from yacc or lex, which may do any number of strange things.
Re: How I wrote a self-hosting C compiler in 40 days
#27Long ago UNIX had compiler writing tools like yacc and lex. I wonder if they are useful for exercises like this.
Re: How I wrote a self-hosting C compiler in 40 days
#28http://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.
Re: How I wrote a self-hosting C compiler in 40 days
#29For 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.
Re: How I wrote a self-hosting C compiler in 40 days
#30For 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.