A Simple C Compiler Written in C For Compiler Course Project.
It aims only to compile a subset of C Standard to MIPS Assembly.
The generated MIPS code can thus be run on any MIPS simulators or in real environment that supports MIPS. For testing purposes I run the code on QtSPIM, a good multi-platform MIPS simulator.
- Basic operations (e.g. addition multiplication less than operation bitwise negation etc.)
- Comments (
// fooand/* foo */) - Sequences of statements (
foo; bar) - Return statements
- If statements and else statements
- Local variables
- Basic varibale types (only
floatandintis supported) - Variable assignment
- While loops (
while (foo) { bar }) - Function calls
- Binary expression
- Unary expression
- Only supports
inttype to be compiled, but provide syntax and semantic checks for all types - No preprocessors
- No
breakstatement
The project is managed by CMake and needs flex and bison installed to compile the code.
Simply run
mkdir build
cd build
cmake ..
makeAnd the compiler is ready to use. In the tests directory are some basic tests I personally use to test the compiler, including some with intentional syntax and semantic errors.
To compile the source code using the compiler, run
./scc /path/to/source_file.cAnd to enable debug output, run
./scc /path/to/source_file.c -i -sWill output intermediate result such as intermediate instructions(-i) and syntax tree(-s).
-o will set the path for the assembly code output.
MIT.