4 ms·
I actually found the code surprisingly easy to read; "tk" stands for "token", "ty" for "type", and so forth. It's worth noting that compilers don't pop out of
by cbhl 12y ago
I actually found the code surprisingly easy to read; "tk" stands for "token", "ty" for "type", and so forth.
It's worth noting that compilers don't pop out of thin air -- you have to start with something simple in order to compile a more complicated compiler. Bootstrapping your own self-hosting compiler is a useful academic exercise, and you should try it sometime if you haven't already: http://en.wikipedia.org/wiki/Bootstrapping_(compilers) http://en.wikipedia.org/wiki/Bootstrapping_(compilers)
- marcofiset 12y agoWell, if this particular compiler is defined in 4 functions, why couldn't it be made out of more functions, enhancing the readability and maintainability of the code?
- afandian 12y agoWho says it's designed to be maintainable? Not everyone writes code for the reason that everyone else does.
- cbhl 12y agoThere is no reason why couldn't it be made out of more functions. Absolutely none. In fact, you can fork the repository and do the refactoring yourself, right now. If I had to guess, the functions are tied pretty closely to how the author is parsing the file; "next" (next token), "expr" (expression), "stmt" (statement), and "main". As for the project being called "C in 4 functions"; at best, I'd argue that's just a linkbait-y title since it's not actually C (it's a subset). I don't have a problem with the code _per se_; just the title.