Follow

anyone know a good book or blog post or something about how to write a c compiler

@SuricrasiaOnline Sy Brand did a talk about it where they basically write one in an hour

@mrbeanbag hmm I could only find them writing a brainfuck compiler

@SuricrasiaOnline tbh i didn't actually watch it but i remember them tweeting about it

@SuricrasiaOnline There's “A Retargetable C Compiler: Design and Implementation” which includes the code of a C compiler as a literate program. It's quite old so you might need to adapt it to a modern istruction set.

@noiob @SuricrasiaOnline that book actually *is* about that LLVM. first Japanese LLVM text, illustrated, and first promoted as a doujin work at Comiket (if I'm understanding correctly)
llvm.moe/

@SuricrasiaOnline Fabrice did a couple of compilers -- fbcc a while back bellard.org/fbcc/

And TCC is actually useful

bellard.org/tcc/

I think openbsd is continuing tcc dev? Or maybe it was pcc they're using. Found this interesting page briancallahan.net/blog/2021101

@SuricrasiaOnline

Your chart is ready, and can be found here:

solipsys.co.uk/Chartodon/10729

Things may have changed since I started compiling that, and some things may have been inaccessible.

The chart will eventually be deleted, so if you'd like to keep it, make sure you download a copy.

@SuricrasiaOnline "An Incremental Approach to Compiler Construction" is a good paper on how to broadly approach it imo, check out 8cc, tcc, and chibicc, the specs themselves are surprisingly nice to read...i reckon it depends on what you want out of it tho, like do you wanna rely on other tools and libs like yacc / lex / llvm or do everything fresh? fully spec conformant cc or learning project?

@nea largely a learning project, nothing intended to be used seriously. I read that yacc was one of the first things ever implemented in the c language, so I'm interested in reenacting that history

@SuricrasiaOnline hell yeah! Parser theory is so interesting and it’s way cooler to do a LALR like yacc instead of a regular degular recursive descent parser. Being a learning project is sick bc the most cursed part of a cc is the semantics of the spec so u can just sidestep that entirely and engage with it on your terms. V cool

Sign in to participate in the conversation
Cybrespace

cybrespace: the social hub of the information superhighway jack in to the mastodon fediverse today and surf the dataflow through our cybrepunk, slightly glitchy web portal support us on patreon or liberapay!