4 ms·
C became popular because it's easy to implement– the syntax is easy to write a compiler for.
by crazypython 6y ago
C became popular because it's easy to implement– the syntax is easy to write a compiler for.
- glouwbug 6y agoIt really isn't... The grammar isn't formal. For instance: person * me; Is this a multiplication statement, or a pointer to a person typedef?
- kazinator 6y agoBut that's the easy part of writing a compiler anyway. All we do is, right in the lexical analyzer (not ever the parser) look up the person identifier in the table of declared identifiers in the current scope. It then returns the identifier as a type-identifier, object-identifier or undeclared-identifier. These are then referenced in the grammar phrase structure rules as necessary. I think there was an aspect of writing a C compiler that was easier, which was namely that certain optimizations in C were just left to the programmer. To get good code out of C, you depended on the basics, like decent instruction selection and peephole optimization, and jump-threading, and maybe elimination of dead code. Then to otherwise get good code out of C, you stuffed multiple side effects into a single expression, which allowed the compiler the generate the computation and storage accesses any order without analyzing whether any particular order is correct (ensuring they are all correct was left to the programmer, who often didn't care as long as the one compiler he or she were using gave them the right results). Even the assignment of local variables to registers was programmer-hinted: C had the (now deprecated) register keyword. With the register keyword, your compiler just had to place those variables in registers which were marked with it, and screw the rest. No analysis about which ones should be in registers: particularly good in register-starved architectures. The microcomputer world was characterized mainly by register-starved architectures, with the notable exception of the Motorola 68K series.
- kazinator 6y agoC is no easier to write a compiler for than Modula 2 or any such C alternative that was relevant in the 80s.