A Flask-based web application that visualizes all 7 phases of compilation for arithmetic expressions.
-
7 Compilation Phases Visualization:
- Lexical Analysis (Tokenization)
- Syntax Analysis (AST Generation using Recursive Descent Parser)
- Semantic Analysis
- Intermediate Code Generation (3-address code)
- Code Optimization (Constant Folding)
- Code Generation (Assembly)
- Target Code Optimization
-
Symbol Table Management: Variables are mapped to identifiers (id1, id2, etc.)
-
Fully Offline: No external dependencies required at runtime
-
Interactive Dashboard: Clean visualization of all phases side-by-side
-
Support for:
- Arithmetic operators: +, -, *, /
- Parentheses for grouping
- Multiple variables
- Assignment expressions
- Clone the repository:
git clone https://github.com/Anorak001/Compiler.git
cd Compiler- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Start the Flask server:
python app.py- Open your browser and navigate to:
http://localhost:5000
-
Enter an arithmetic expression (e.g.,
x = a + b * 60) and click "Compile" -
View all 7 compilation phases and the symbol table
x = a + b * 60result = (a + b) * (c - d)y = 5 + 3 * 2z = (10 + 20) / 2
- Lexer (
compiler_phases/lexer.py): Tokenizes input into meaningful tokens - Parser (
compiler_phases/parser.py): Uses recursive descent to build an AST - Semantic Analyzer (
compiler_phases/semantic_analyzer.py): Validates semantics - Intermediate Code Generator (
compiler_phases/intermediate_code_generator.py): Generates 3-address code - Optimizer (
compiler_phases/optimizer.py): Performs constant folding - Code Generator (
compiler_phases/code_generator.py): Generates assembly code - Target Optimizer (
compiler_phases/target_optimizer.py): Optimizes assembly code
- Frontend: HTML, CSS, JavaScript (vanilla)
- Backend: Flask
- All assets are local - no CDN dependencies for offline functionality
- Backend: Python 3.x, Flask
- Frontend: HTML5, CSS3, JavaScript (ES6+)
- Parser Type: Recursive Descent Parser
See LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.