How moise7000/mini-python-compiler works
Project Type and Purpose
• This is a compiler tool (“Pytator Compiler”) for a Mini-Python dialect.
• Core functionality:
• Lexical analysis → token stream
• Syntactic analysis → syntax tree
• AST generation (exported in DOT format)
• (Future: ASM code generation)
• Two “front ends”:
• CLI Java application (java -jar pytator.jar …)
• Web interface (Flask app packaging the JAR via Docker)
High-Level Components
a. Frontends
• Java CLI runner (Main.java)
• Python Flask web UI (utils/web_interface/app.py + templates)
b. Compiler Core (all under src/)
1. Lexical Analyzer (src/analysis/lexical)
2. Syntax Analyzer (src/analysis/syntaxic)
3. Token definitions (src/analysis/tokens/…)
4. Common utilities & symbol table (src/analysis/common)
5. AST representation & DOT conversion
c. Resources
• Grammar definitions (resources/grammaires)
• Example and test source files (resources/fichier_tests, examples/)
d. Post-processing
• Graphviz → SVG converter (utils/graphviz_code_to_svg.py)
e. Infrastructure
• Docker compose file (utils/web_interface/compose.yaml + Dockerfile)
• JAR packaging metadata (resources/META-INF/MANIFEST.MF)
f. Tests
• JUnit tests (tests/analysis/…)
Data Flow and Interactions
• Input Stage
• User provides a .py file via CLI or Web UI
• Grammar files loaded at startup by the Syntax Analyzer
• Processing Stage (Java runtime)
1. Main.java parses command-line flags
2. LexicalAnalyzer reads characters → TokenManager → Token stream
3. SyntaxAnalyzer consumes tokens + grammar → parses → builds AST (AbstractSyntaxTree)
4. DotToAssertConverter (and PrettyPrinter) serializes AST to DOT format
• Output Stage
• DOT file generated to disk or returned via HTTP
• Graphviz converter (Python) reads DOT → outputs SVG/PNG
• Web UI serves front-end HTML that displays SVG
Architectural Patterns & Principles
• Pipeline pattern: clear separation of lexer, parser, AST builder
• Modular token definitions via subpackages (delimiters, operators, keywords)
• Strategy pattern for token helpers (identhelpers)
• Layered design: CLI/Web UI layer → Compiler core → Post-processing → Presentation
• Dependency injection of grammar files
Final Checklist
• [ ] All core modules are represented
• [ ] Data flows are directional and annotated
• [ ] External dependencies (Docker, Graphviz) are included
• [ ] Labels are clear and components are named exactly as in the codebase