A compiler for C-subset language implemented in Python
Source Code → Lexer → Parser → Semantic → IR → ASM
Features:
- Lexer (Tokenization)
- Recursive Descent Parser + AST
- Semantic Analysis + Symbol Table
- Quadruple IR Generation
- 16-bit x86 ASM CodeGen
- CLI + GUI + Web Interface
- Web UI with adaptive light/dark theme and Chinese / English switcher
git clone https://github.com/zhouder/compiler.git
cd compiler
python src/main.py examples/test.cNote: The
output/directory is empty on first clone. Running the commands above will generate the output files automatically.
Output files:
output/test.tokens.txt— Tokensoutput/test.ast.txt— ASToutput/test.ir.txt— IR (Quadruples)output/test.asm— ASM (x86)
# GUI
python src/gui.py
# Web (visit http://127.0.0.1:8000)
python -B src/webapp.pycompiler/
├── examples/
│ └── test.c # Test source
├── src/
│ ├── lexer/ # Lexer
│ ├── parser/ # Parser + AST
│ ├── semantic/ # Semantic Analysis
│ ├── ir/ # IR Generation
│ ├── codegen/ # Code Generation
│ ├── main.py # CLI entry
│ ├── gui.py # GUI entry
│ └── webapp.py # Web entry
└── output/ # Generated files
| Feature | Description |
|---|---|
| Types | int, char, float, void |
| Struct, Pointer | User-defined types |
| Functions | Definition, parameters, calls |
| Arrays, Struct Variables | Complex data types |
| Expressions | Arithmetic, relational, logical |
| Control Flow | if/else, while, for, do while |
| I/O | printf, scanf |
| Type Checking | Scope, symbol table, type checking |
Requires DOSBox for 16-bit execution (replace D:\compiler\output with your actual output/ path):
mount c D:\compiler\output
c:
masm test.asm;
link test.obj;
testMIT License — see LICENSE
