I am interested in writing a very minimalistic compiler.
I want to write a small piece of software (in C/C++) that fulfills the following criteria:
- output in ELF format (*nix)
- input is a single textfile
- C-like grammar and syntax
- no linker
- no preprocessor
- very small (max. 1-2 KLOC)
Language features:
- native data types: char, int and floats
- arrays (for all native data types)
- variables
- control structures (if-else)
- functions
- loops (would be nice)
- simple algebra (div, add, sub, mul, boolean expressions, bit-shift, etc.)
- inline asm (for system calls)
Can anybody tell me how to start? I don't know what parts a compiler consists of (at least not in the sense that I just could start right off the shelf) and how to program them. Thank you for your ideas.