TinySol is a sophisticated source-to-source compiler that translates a subset of a high-level programming language (TinySol) to Brainfuck, a minimalist Turing-complete programming language. This project demonstrates advanced compiler design principles, including abstract syntax tree (AST) manipulation, memory management, and code generation.
- Modular translation architecture
- Support for complex computational scenarios
- Turing-complete translation
- Extensive test coverage
- Flexible and extensible design
The translation process is broken down into specialized modules:
-
Memory Management (
memory_manager.py
)- Tracks memory allocation
- Manages memory cell tracking
- Supports complex memory operations
-
Base Translator (
base_translator.py
)- Provides core translation utilities
- Implements fundamental translation methods
-
Arithmetic Translator (
arithmetic_translator.py
)- Handles arithmetic operations
- Translates multiplication, addition, and modulo operations
- Implements complex Brainfuck arithmetic algorithms
-
Condition Translator (
condition_translator.py
)- Manages conditional logic translation
- Supports various comparison and logical operations
-
Expression Translator (
expression_translator.py
)- Translates complex expressions
- Handles binary and unary expressions
- Manages memory cell allocation for expressions
-
Statement Translator (
statement_translator.py
)- Translates programming constructs
- Supports variable declarations
- Handles loops and conditional statements
-
Node Translators (
node_translators.py
)- Orchestrates the overall translation process
- Coordinates between different translation modules
- Variable declarations
- Arithmetic operations (+, -, *, /)
- Comparison operations (==, <=, <, >, >=)
- Logical operations (&&, ||)
- For loops
- Conditional statements (if)
git clone https://github.com/steake/TinySol.git
cd TinySol
pip install -r requirements.txt
python run_tests.py
# TinySol code
tinysol_code = """
int n = 5;
int factorial = 1;
for (int i = 1; i <= n; i++) {
factorial = factorial * i;
}
"""
# Translate to Brainfuck
brainfuck_code = translate_to_brainfuck(tinysol_code)
- Subset of language features supported
- Complex computational scenarios may require optimization
- Performance overhead due to translation complexity
- Enhanced arithmetic algorithms
- More comprehensive language support
- Performance optimizations
- Additional test cases
Contributions are welcome! Please submit pull requests or open issues on GitHub.
GitHub: @steake