How marwanair/tinypy-generator works
Project type and purpose
• This is an open-source code-generation tool (TinyPy Generator) written in Python.
• Purpose: automatically generate Python programs at varying levels of complexity (arithmetic, conditionals, loops) via a context-free grammar (CFG).
File structure
• Top-level files:
• code_generator.py – main Python script (CLI entry point and generator engine)
• requirements.txt – Python dependencies
• README.md – usage and project description
• example.ipynb – interactive demonstration
• data/ directory: contains sample/generated program outputs (data_1.1.txt, data_1.2.txt, …, data_all.txt)
• No separate front-end/backend: single CLI tool with optional notebook interface.
README for additional insights
• Uses command-line arguments: num_programs, level, filename, deduplicate
• Describes generator levels (1.1 → 3.2, plus ALL) mapping to CFG rules
• Encourages modification and extension
a. Main components
1. Command-Line Interface (CLI)
2. Argument Parser (e.g., argparse)
3. Generator Engine
• CFG Rule Loader (internal module or code block within code_generator.py)
• Program Synthesizer (applies grammar rules to build AST/code strings)
4. Deduplication Module (optional step)
5. File I/O
• Input: data/ (optional seed or sample data)
• Output: target file (e.g., data/data.txt or user-specified filename)
6. Example/Notebook Interface (example.ipynb)
b. Relationships and interactions
• User → CLI → Argument Parser → Generator Engine → (Deduplication) → File Writer
• Generator Engine → may read/write data/ folder for intermediate or sample data
• Notebook → imports code_generator functions to demonstrate usage
c. Architectural patterns/design principles
• Single responsibility per module: parsing, generation, deduplication, I/O
• Pipeline flow: linear stages with clearly defined inputs/outputs
• Extensibility point: adding new grammar levels or custom rules
d. Relevant technologies/frameworks/libraries
• Python 3.x
• argparse or click (for CLI)
• Standard library (os, sys, random)
• Jupyter Notebook (for example.ipynb demonstration)