r/Compilers • • May 16 '26

Help: Writing a Python to C transpiler

I'm thinking about embarking on a journey for writing a Python to C transpiler. It'll provide an interesting challenge and also will be useful, considering I am targeting an environment that can only take a subset of C as input. Given that I haven't ever written a compiler but I have written an interpreter about a decade ago and have forgotten most of the process, what are some things I'd need to familiarize myself with in order to write this transpiler? Also, what intermediate representation would be wise for such a project?

14 Upvotes

13 comments sorted by

View all comments

Show parent comment

7

u/Inconstant_Moo May 17 '26

Or in order to properly transpile Python's decorators you have to understand preprocessing and macros in C.

Not necessarily, because the transpiler is generating C anyway, so you don't have to write a bit of C that generates C.