Course work (a C0 compiler) for BUAA B3I063410 Compiler Design.
Students will be required to design and implement a C0 compiler in 6 weeks, step by step. From lexical analysis, syntax analysis to semantic analysis (Quaternary mid-code generation included) and finally, to mips code generation and optimization.
- Source Code
- Final release version
- No optimization version
- Documents
- My design thoughts
- Software Documentation
- Test input
- Some test programs
- C0 grammer.txt
- Detailed C0 grammer requirements
This is a Visual Studio 2017 projects, you could open it directly with VS17.
Once you start the program, you could press directly to compile the default 15061200_test.txt
or you could input the full path
of your own test program.
The compiler's output should include:
File Name | Contents |
---|---|
output_after(before).asm | Mips code |
syntac_output_after(before).txt | Quaternary Mid Code |
After that, you could run the generated mips code with Mars_refreshfix.jar
.
In SyntacticAnalyze.cpp
, you can decide whether to optimize the output or not.
#include "genMips.h"
//#include "genMips_opt.h"
In myconst.h
, it's on your choice that
const bool Verbose = true;// if true then no detailed syntac info output in console
const string Subfix = "before";// set this to after and your output file will be named with subfix '_after'
const string Newline = "";//Newline = "\\n" if you want to beautify the mips runtime output (automatic line feed)
- Start earlier and make your own plan !
- Don't forget what you have learnt in class.
- Review your design with pens and papers (debug from higher level) and don't rely too much on testing.
Many thanks to my dear friend @ZhaoYi1031 who inspires me a lot. Also, great work by Pete Sanderson (programming) and Ken Vollmar. Their MIPS Assembler and Runtime Simulator (Mars) runs smoothly.