This project implements a simple Mini-C compiler pipeline for a compiler design developed as an academic compiler design project.
- Lexical analysis (tokens for keywords, identifiers, literals, operators, delimiters)
- Syntax analysis using a recursive descent parser
- AST generation
- Semantic analysis:
- Redeclaration checks
- Undeclared variable checks
- Type mismatch checks (
intvsfloat) - Array usage and static bounds checks for literal indices
- IR generation as Three-Address Code (TAC)
ast_nodes.py: AST node definitionslexer.py: Lexer implementationparser.py: Parser + AST constructionsemantic.py: Symbol table + semantic checksir_gen.py: TAC generationmain.py: Pipeline entry pointtest_program.mc: Valid Mini-C sampletest_errors.mc: Invalid Mini-C sample (semantic errors)
From this folder:
python main.py test_program.mc --tokens --ast --symbols --tac output.tacExpected behavior:
- Prints tokens, AST, symbol table, and TAC
- Writes TAC to
output.tac
Test error handling:
python main.py test_errors.mc --symbolsExpected behavior:
- Prints symbol table
- Reports semantic errors with line numbers
- Variable declarations:
int x;,float y = 1.5; - Array declarations:
int arr[10]; - Assignments:
x = 3 + y;,arr[i] = x; - Control flow:
if-else,while,for - Printing:
print(expr); - Arithmetic and relational operators
ffd2182 (Reorganize project structure and remove virtual environment)