A Python implementation of a compiler pipeline for a subset of the C programming language.
-
Full compiler pipeline implementation:
- Lexical Analysis (Tokenizer)
- Syntax Analysis (Parser)
- Semantic Analysis
- Intermediate Code Generation
- Code Optimization
- Target Code Generation
-
Supported C constructs:
- Variable declarations
- Arithmetic operations
- Function definitions
- Return statements
- Python 3.6+
- Clone repository:
https://github.com/mdzubayerhossain/C-Compiler-Project-With-Pyhton.git cd C-Compiler-Project-With-Pyhton
``bash
int main() {
int result = 2 + 3 * 4;
return result;
}
``bash
global main
main:
mov t1, 3
mov t2, 4
mul t1, t2
mov t3, 2
add t3, t1
mov result, t3
mov eax, result
ret
' ============================================= ' COMPILER COMPONENTS ' =============================================
Public Module CompilerComponents
' -----------------------------------------
' Lexical Analysis Module
' -----------------------------------------
' Tokenizes input using regular expressions
' Identifies:
' - Keywords (e.g., "int", "return")
' - Identifiers (variable names)
' - Literals (numeric values)
' - Symbols (operators and punctuation)
' -----------------------------------------
' Syntax Analysis Module
' -----------------------------------------
' Implements recursive descent parser
' Constructs Abstract Syntax Tree (AST):
' - Node-based hierarchy
' - Represents program structure
' - Validates grammar rules
' -----------------------------------------
' Intermediate Code Generation
' -----------------------------------------
' Generates Three-Address Code (TAC):
' - Temporary variables
' - Simple operations
' Performs optimizations:
' - Constant folding
' - Dead code elimination
' -----------------------------------------
' Target Code Generation
' -----------------------------------------
' Outputs x86 assembly code with:
' - Basic instructions (MOV, ADD, etc.)
' - Register allocation strategy
' - Stack management
' Generates:
' - Section headers
' - Function prologues/epilogues
' -----------------------------------------
' Current System Limitations
' -----------------------------------------
Const LIMITATIONS As String() = {
"Supports limited C syntax subset",
"No advanced type checking",
"Simplified memory management",
"Basic error handling",
"Limited optimization passes",
"No support for pointers"
}
This README:
- Provides clear usage instructions
- Shows sample input/output
- Includes architecture visualization
- Lists key components and limitations
- Uses proper markdown formatting
Would you like me to modify any section or add specific details?