> I suspect that he [Dennis Ritchie] invented a syntax, wrote code for it, which turned out to be more complicated than he had expected. And that was eventually standardized by the ANSI committee. It's hard to implement a standardized language because you have to get everything right. It's rather easy to write your own toy language. Love those lines
It's actually a clone of BCPL, which invented keywords & "programmer in charge philosophy." They ported it to PDP's with a few changes for UNIX. Standards came later. Specific details every step of the way are here: http://pastebin.com/UAQaWuWG
How I wrote a self-hosting C compiler in 40 days
101–110 of 128 posts
Re: How I wrote a self-hosting C compiler in 40 days
#102Earlier quoted context omitted.
Out of curiosity - why do you consider cpp particularly hard? It's easier than the compiler, actually :)
Well... easier than the compiler but very hard to do the last 20% (I never had the time; hobby project) because docs are so hard to find. Or at least were--maybe that's changed.
Re: How I wrote a self-hosting C compiler in 40 days
#103Earlier quoted context omitted.
May of these issues are still relevant to embedded systems with limited resources.
If you really want to compile something on an embedded system, you'd be much better off with something like Forth anyway.
Re: How I wrote a self-hosting C compiler in 40 days
#104Earlier quoted context omitted.
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.
Or even better, GLL. http://dotat.at/tmp/gll.pdf
Re: How I wrote a self-hosting C compiler in 40 days
#105Earlier quoted context omitted.
This is completely contrary to my experience, in which parser generators have not paid for themselves. Writing a parser by hand in C is generally easier and less time-consuming over the long run than struggling along with a parser generator, especially if you have any interest in producing useful syntax error messages or recovering from other kinds of errors in some useful way. I agree that almost none of the importa…
I wrote a parser-generator in C and it took less than 42 days. Your mileage may vary. https://github.com/gregtour/parsergenerator Most of the C code is less than 1.5k LOC for the functional part, and this minimal, self-compiling C compiler has a parser that is nearly 3,000 lines long. Even if it took 1,000 lines of extra code for the non-LR aspects of C's grammar, I think it would be the same amount of work. This jus…
http://preccx.sourceforge.net/
This was long before I discovered the simple joys of squeezing out unnecessary CPU cycles from my own hand-rolled self-directed lexer/parsers.
Re: How I wrote a self-hosting C compiler in 40 days
#1061) write compiler 2) get a job at google . . 4) profit
I was already working at Google full-time (for an unrelated project) when I was writing this in my spare time.
Re: How I wrote a self-hosting C compiler in 40 days
#107Earlier quoted context omitted.
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.
Or even better, GLL. http://dotat.at/tmp/gll.pdf
Although, to be fair, PEG (Packrat) do support left recursion [1], and it can also be combined with Pratt for the binary expressions very efficiently, at O(n).
Re: How I wrote a self-hosting C compiler in 40 days
#108I really enjoyed reading this. It's informative, fun, and has a refreshingly honest tone. Too often, stories passed around by computer scientists entail clever solutions and elegant insight striking the protagonist like lightning in the hour of need. Rarely does the programmer express regret, make self-corrections, and confront fear and doubt along the way: >I should have written beautiful code from the beginning, bu…
I agree with that part. You know you're looking at genuine science or art in software development when you see those things. Because they're always there tackling new, hard problems.
Re: How I wrote a self-hosting C compiler in 40 days
#109Earlier quoted context omitted.
Well... easier than the compiler but very hard to do the last 20% (I never had the time; hobby project) because docs are so hard to find. Or at least were--maybe that's changed.
What docs? It's all in the standard
Re: How I wrote a self-hosting C compiler in 40 days
#110What do you mean, "as a child"?