Very cool! I can’t imagine writing everything in C, I’m currently learning this in OCaml which seems nicer for a project like this.
MisterTea 6 hours ago [-]
> I can’t imagine writing everything in C
I will say that C is a perfect low level language for bootstrapping more complex systems and languages. If I were building a bootstrap compiler I would write it in C and have it emit C. Specifically C89/99 ONLY with no POSIX/GNU deps. that will guarantee a large swath of compiler and system support out of the box.
cxr 1 hours ago [-]
> C is a perfect low level language for bootstrapping more complex systems and languages. If I were building a bootstrap compiler I would write it in C and have it emit C
The best thing that C has going for it over alternatives* is that "C89" and "C99" refer to very specific things, and they're things that people strongly associate with what it means to be "writing C" (whereas something like "Pascal" could refer to any one of a bunch of different dialects).
Even so, with my bias for C and the C-like curly brace languages that it influenced, and my wholeheartedly agreeing with what Kernighan wrote in "Why Pascal Is Not My Favorite Programming Language" (and my belief that K&R is one of the best products of technical writing ever produced, despite the criticism it receives in the 21st century), I've come to appreciate and accept that Wirth's work that eventually resulted in the Pascal→Modula→Oberon progression is better** (even with its harsh and unappealing grammar; if you were really pursuing this as an exercise, then it's not hard to write a different lexer—the easiest part of the compiler to understand and modify—and re-tool the language with minor tweaks so modules have implicit scope and everything is curly braces). This would be true even if C's only problem were its ongoing lack of modules in lieu of leaning on the C preprocessor—and, to be sure, that's not the only problem (though it is a big one). The snappiness of Wirth's one-pass compilers and their serving as an existence proof that even seemingly complex jobs like compiling a program can actually be simple is another thing worth the price of admission alone.
* for the specific use case mentioned: a "low level language for bootstrapping more complex systems"
Unlike how a bunch of projects end right as they start to get good, this has a great ending. Thank you
Previously:
12 comments; 156 points. 2022 November 29. <https://news.ycombinator.com/item?id=33788013>
67 comments; 484 points. 2020 January 8. <https://news.ycombinator.com/item?id=21968420>
I will say that C is a perfect low level language for bootstrapping more complex systems and languages. If I were building a bootstrap compiler I would write it in C and have it emit C. Specifically C89/99 ONLY with no POSIX/GNU deps. that will guarantee a large swath of compiler and system support out of the box.
The best thing that C has going for it over alternatives* is that "C89" and "C99" refer to very specific things, and they're things that people strongly associate with what it means to be "writing C" (whereas something like "Pascal" could refer to any one of a bunch of different dialects).
Even so, with my bias for C and the C-like curly brace languages that it influenced, and my wholeheartedly agreeing with what Kernighan wrote in "Why Pascal Is Not My Favorite Programming Language" (and my belief that K&R is one of the best products of technical writing ever produced, despite the criticism it receives in the 21st century), I've come to appreciate and accept that Wirth's work that eventually resulted in the Pascal→Modula→Oberon progression is better** (even with its harsh and unappealing grammar; if you were really pursuing this as an exercise, then it's not hard to write a different lexer—the easiest part of the compiler to understand and modify—and re-tool the language with minor tweaks so modules have implicit scope and everything is curly braces). This would be true even if C's only problem were its ongoing lack of modules in lieu of leaning on the C preprocessor—and, to be sure, that's not the only problem (though it is a big one). The snappiness of Wirth's one-pass compilers and their serving as an existence proof that even seemingly complex jobs like compiling a program can actually be simple is another thing worth the price of admission alone.
* for the specific use case mentioned: a "low level language for bootstrapping more complex systems"
** ibid, for emphasis
?
https://holub.com/compiler/
It is called Practical Compiler Construction. The Compiler Writing Journey is based on it.