4 ms·
There's a very interesting C interpreter/compiler there [1]. From the header: "c is the c compiler. It takes a single source file and creates an executable fi
by seansh 3y ago
There's a very interesting C interpreter/compiler there [1]. From the header:
"c is the c compiler. It takes a single source file and creates an executable file or else executes the compiled code immediately. The compiler does not reach full standards compliance, so some programs need minor adjustment.
There is no preprocessor, although the #include keyword is allowed supporting a single level of file inclusion."
[1] https://github.com/rswier/swieros/blob/master/root/bin/c.c https://github.com/rswier/swieros/blob/master/root/bin/c.c
- speps 3y agoThe parser actually supports #define and #undef as well.
- Paul-Craft 3y agoYou know what I find amusing about the C compiler? It's about the same size as the kernel in terms of LOC. I don't know why, but that amuses me. This whole project just really makes me happy. I think it's because it's obviously a labor of love, it's very UNIX-y, yet at the same time, utterly comprehensible. I think this is a nicer environment for just general screwing around than a PDP-11 emulator running real V6. The core looks to be all here, without having to bear the weight of complexity implied by a real implementation. 10/10 will clone and study.
- peter_d_sherman 3y agoAgreed! This C compiler, at ~2297 LOC (this number includes empty lines, actual LOC is less) -- is certainly worthy of being included in the group of small C compilers for study! 9.5/10 for me (could still be smaller and could still be better documented -- as could all other small OS'es/compilers -- so not a criticism -- a global group observation!)... but that being said, kudos to the author for what was no doubt a lot of hard work! Well done!
- blacksqr 3y agoI haven't looked closely, but this appears to be the C4 compiler (or an update to it), which has been around for a while and is worthy of attention in itself.
- seansh 3y agoThe C4 compiler is certainly fascinating and worth studying but don't believe that swieros's C compiler is based on that judging by their code [1][2]. There are similarities of course but well they are compiling the same language after all using some similar standard techniques like recursive descent parser [3]. Anyways, C4 is also very cool and focused on minimalism. Swieros's compiler seems much more extensive and even includes #define as the other comment mentioned and va_args. [1] https://github.com/rswier/swieros/blob/master/root/bin/c.c https://github.com/rswier/swieros/blob/master/root/bin/c.c [2] https://github.com/rswier/c4/blob/master/c4.c https://github.com/rswier/c4/blob/master/c4.c [3] https://en.wikipedia.org/wiki/Recursive_descent_parser https://en.wikipedia.org/wiki/Recursive_descent_parser
- seansh 3y agoOh I completely missed the fact that they're both written by the same person.