A C compiler written in C.
My goal for this project is to learn how compilers work by building a functional compiler. So far I've implemented a lexer, a parser and code generation. Currently it supports:
- arithmetic operators:
+,-,*,/ - unary operators:
-,~,! - increment/decrement: prefix
++x,--xand postfixx++,x-- - comparison operators:
<,>,<=,>=,==,!= - logical operators:
&&,|| - ternary conditional:
cond ? a : b - local and global variable declarations, assignments, and references
- compound assignment:
+=,-=,*=,/= if/elsestatementswhileloopsforloopsbreakandcontinue- multiple functions with up to 6 parameters and calls
voidreturn type and barereturn;- pointers:
int *p, address-of&x, dereference*p, pointer parameters - pointer arithmetic:
p + n,p - n,p++,p--, pointer difference, andp[i]indexing //line comments and/* */block comments
make
./redix input.c
gcc -o out out.s
./out
make test
Test files live in tests/. Each file has a // expect: N comment on the
first line indicating the expected exit code.
MIT