I'm trying to make a program that takes a c file and converts it into python code and was wondering if something already exists that is similar. Basically, I will input a simple file in c with normal c features and the program will have to output the same program but in python instead.
Thanks in advance, Ankit
CodePudding user response:
The simplest answer to your question is just "no". Coding is a complicated process which requires creativity and nuance, and we're not really at the stage where a program can do that.
You could probably create something which you can input Python into and it outputs C for the equivalent command for basic things like "print", "for i in range(n):" etc but more complicated stuff is going to require a human at least for now.
I tried to do the same thing to turn Python into Java. It didn't go well and I concluded that it's basically impossible or at least much harder than I thought.
CodePudding user response:
You have to make c compiler that generate python code. Try to see if you can learn how c is written to convert it to python. You could also use awk Unix command to make a basic interpreter line by line. The first thing to do may be to have clean formatted c code to enable easy translation :
- { => add at end of code line and increment indentation by 4 spaces
- } => decrement indentation by 4 spaces
- ; => end of line
- …
It may be huge work.