A lightweight, single-pass transpiler written in C++ that converts a subset of Python syntax into C. Includes lexical analysis, recursive descent parsing, and strategic code emission.
The transpiler currently supports the following syntax mapping:
| Feature | Python Syntax | Generated C Equivalent |
|---|---|---|
| Printing | print("hello") or print(x) |
printf("hello\n"); or printf("%.2f\n", x); |
| Loops | for i in range(1, 10): |
for (float i = 1; i < 10; ++i) { ... } |
| Conditionals | if x > 5: |
if (x > 5) { ... } |
| Input | x = input() |
float x; scanf("%f", &x); |
| Assignments | y = (10 + 5) * 2 |
float y = (10 + 5) * 2; |
total = 0
iterations = input()
for i in range(iterations):
if i > 5:
print(i)
total = total + i
print("Finished")#include <stdio.h>
int main() {
float total = 0;
float iterations;
scanf("%f", &iterations);
for (float i = 0; i < iterations; ++i) {
if (i > 5) {
printf("%.2f\n", i);
total = (total + i);
}
}
printf("Finished\n");
}This project uses CMake to manage the build process. Ensure you have a C++20 compatible compiler installed.
Create a build directory, then generate the build files with this command:
mkdir build
cd build
cmake ..