The beginnings of a C compiler
Date: 2021-10-10
I've just recently had this idea. I've seen an post on Twitter for a programming competition right for my age group, and I decided I want to join, but I had no idea what I wanted to do for it. After a few days of thinking however, I came up with an idea: I'll write my very own C compiler.
Of course, this is a pretty big project, so I set up the following rules for myself:
- In the beginning at least, only implement ANSI C89 and no more
- Don't try to generate machine code directly. Use assembly if there's enough time, if there isn't, use some code generator like QBE
- For the time being, only compile to Linux x86 (or AMD64, I'm not sure yet, actually), or in general only for a single architecture
I've also set out to achieve the following things:
- A working ANSI C compiler that can compile itself (which means the compiler also has to be written in pure ANSI C)
- A compiler that does not depend on anything but the ANSI C standard library, i.e. not even POSIX libraries
With these goals in mind, I'm starting the project. Wish me luck!