China University of Petroleum (East China)-Compiler Theory Course Design-Group Two
The project is inspired by Chibicc, thanks to rui314 for the open-source project 💖.
The graphical interface adopts Fluent 2 design style and is implemented using PyQt6 and PyQt-Fluent-Widgets 🌟.
Incomplete version, lacking interpreter implementation.
Supported variable types: int, char, int*, char*, int[], char[]
Run literal constants.
Supported operators: + - * / % == != < <= > >= && || ! = & ^
Supports pointers, dereferencing, function definition, and function invocation.
Supports IF-ELSE, FOR, WHILE statements
Implement a class C compiler mimicked by Python that can compile C language code into Intel 80x86 assembly code, equipped with an interpreter to interpret and execute assembly code to obtain computation results. The project also provides a graphical interface, offering some Integrated Development Environment (IDE) functionalities.
- main.py Compiler program entry
- compiler\tokenize.py Lexical analysis, converting source code into Token stored in linked list
- compiler\parse.py: Syntax analysis, converting Token into Abstract Syntax Tree
- compiler\codegen.py Semantic generation, converting Abstract Syntax Tree into assembly code
- compiler\simulator.py Assembly code interpreter
- gui\fluent.py Graphical interface entry
-
Install Python, this project is developed using Python 3.12.0.
-
Install dependencies
pip install -r requirements.txt
-
main.py, provides examples of using the compiler and interpreter.
python main.py
-
interface\fluent.py, provides Pybicc's graphical interface
python interface\fluent.py
int main() { int i=0; int j=0; for (i=0; i<=10; i=i+1) j=i+j; return j; }
int main() { int a=3; int z=5; return a+z; }
int main() { int x=3;int y=5; *(&x+8)=7; return y; }