Refined C Compiler
A new language compiler defined by grammar in guidebook of Compiling Principle in Njtech University. For detailed instructions, please read the pdf file in ./doc
What is it?
A homework made for handling Compiler Principle courses. This project is using lex and yacc, also known as flex and bison. If there is anyone taking this course in Njtech University, this might help you A LOT.
How to use it?
- Download and install your own flex, bison and makefile environment, as all of them are the basic tools for cooking the whole project. As for how to achieve that, you should search for it in yourself.
git clone https://github.com/Autokaka/refined_c_compiler.git
- In termial, input:
maketo compile the compiler. The build files shall be generated “build” directory in your project root directory.
make demoto compile and run an example file to help you understand how to use this simple compiler.
make cleanto clean the generated files and build files.
- if you don’t have Makefile environment, you can run these commands in the root directory of your project in terminal:
./make_all.shto compile the compiler. The build files shall be generated “build” directory in your project root directory.
./make_demo.shto compile and run an example file to help you understand how to use this simple compiler.
./make_clean.shto clean the generated files and build files.
If you need to know the detailed technique about how the script take effect, you can see all of them in
make_demo.sh. Talk is cheap in learning new things, you should always read the code :)
Please notice that the “C” here does not mean that c/c++ language. The language itself has its own rules. The format of your code should follow the definition in ./doc/编译原理上机实验指导书.pdf and ./doc/修改好的LL(1)文法.md
The whole project is built under the following environment. If you have problem in running scripts, please check if you meet the requirements below:
OS: Mac OS Catalina 10.15.5
flex 2.5.35 Apple(flex-32)
bison (GNU Bison) 2.3
Apple clang version 11.0.3 (clang-1184.108.40.206) Target: x86_64-apple-darwin19.5.0 Thread model: posix
Here is the tutorial about how to install lex and yacc: https://www.youtube.com/watch?v=8EO5Y7KhoeU. It is a Youtube link, if you are in a country that cannot access foreign website, please use a VPN first.