I built an open-source Python to C++ AST Transpiler entirely from my phone

calendar_today agoschedule2 min read
— Originally published at dev.to

Hey everyone!

I wanted to share a project I've been pouring my heart into: Astmize. It's an open-source Python-to-C++ transpiler built entirely from my mobile phone (using mobile editors since I don't own a PC at the moment).

Instead of using basic regex or string replacement, Astmize parses Python code into an Abstract Syntax Tree (AST) and maps the logical nodes directly into structurally equivalent, clean C++ code.


The C++ Design Bottleneck I Had to Solve

While developing the transpiler from my screen, I hit a massive roadblock regarding type emission. As we know, C++ is statically typed and strictly forbids using auto for non-static class data members without a direct initialization expression, because the compiler must determine the exact object memory layout at compile time.

In Python, fields are dynamically assigned inside __init__ via arguments (e.g., self.speed = speed). Initially, my compiler emitted auto speed; inside the generated C++ class struct, leading to immediate compilation failures.

The Solution: Smart Type Inference Engine

To fix this from my phone, I implemented a custom Type Inference Engine in the Python backend that utilizes three core heuristics:

  1. RHS Node Evaluation: Evaluates the Right-Hand Side assignment node to detect concrete primitive constants or explicit type initializers.
  2. Variable Tokenization: Automatically splits attribute names by underscores and parses individual tokens against an explicit C++ type keyword library (e.g., detecting is_ or has_ prefixes infers a bool; tokenizing player_speed maps speed to int).
  3. Safe Fallback Mechanism: If the type remains completely ambiguous, it safely defaults to int instead of emitting an illegal auto, ensuring structural layout validity and preventing compilation blocks.

The live dashboard integrates with standard GCC/Clang via the Wandbox API to compile and run the generated C++ code instantly on the fly.


Check it out here:

I'd absolutely love to get your feedback on the generated C++ structure, how you handle strict type emission in metaprogramming/transpilers, and if there are any C++ edge cases I should guard against!

Drop a ⭐ on GitHub if you find the concept interesting! Happy coding!

Image description

146 Points3 Badges3
2Posts
0Comments
18-year-old self-taught Full-Stack Developer passionate about building innovative tools, AI integrations, and optimization. I love breaking complex problems down and building fast solutions—often entirely from my mobile device. Creator of Astmize.
Build your own developer journey
Track progress. Share learning. Stay consistent.
🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

I Wrote a Script to Fix Audible's Unreadable PDF Filenames

snapsynapseverified - Apr 20

Dashboard Operasional Armada Rental Mobil dengan Python + FastAPI

Masbadar - Mar 12

The Sovereign Vault — A Comprehensive Guide to Protocol-Driven AI

Ken W. Algerverified - Jun 4

Tuesday Coding Tip 06 - Explicit template instantiation

Jakub Neruda - Apr 7

Tuesday Coding Tip 02 - Template with type-specific API

Jakub Neruda - Mar 10
chevron_left

Related Jobs

View all jobs →

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!