• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Compiling a programme programmatically

Ok here is what i want to do. I want to create a program (a compiler of sort ) which will run on android that will take a source file written in language that which i have created and will compile that source file into a corresponding program hat will run on android. Tell me that how can i do it. I know that i can develop a debugger for that compiler by using the Android operating system debugger APIs however it is compiling that source file programatically that seems to be the problem and i can't think of a way how to do it. Is there any way that i can do it or it simply is impossible right now on the android.
 
A compiler, or even an interpreter, is no easy task. If you don't know where to begin, you really aren't ready to undertake such an endeavor.

A compiles job is to parse the language of choice, converting it into Assembly code for the target architecture (every architecture has different assembly symbols and registers), optimizing the assembly code in the process. It then takes that assembly code and turns it into object files. Along with the compiler, you will also need to create a linker, which links the object files generated by the compiler, along with any prebuilt libraries, and generates an executable file.
 
I think that you misunderstood what i am attempting to do. I am fully aware that what programming a full fledged compiler on Android entails and since as far as I am aware as Android yet does not have an Assembler that task is impossible for now. What i am trying to do is not to create a full fledged compiler but rather a pseudo-compiler which will take the source file in the language that i have designed (not a full fledged multi-purpose language like C++ of course but rather a language which is created for specifying a set of related tasks and activities) and then create a temporary source file in java which it then can compile by calling the Dalvik compiler like a desktop java compiler and then pass the generated java source file to it and then it will compile that java source file to a Dalvik executable. I know that there are some Android compilers which are able to compile on Android but do they have stand alone compilers which i can call through my program like i can call the java compiler on Desktop computers. And before anyone asks me the reason that why i am trying to do all of this trust me i have a very valid purpose in trying to do all of this.
 
You will need to parse the file, taking into account the syntax of your language, and then create a .java file and a new android project with all of the necessary generated files, then just make a call to android's compiler. Note that this will need to be done on a computer and not an android device, because the android distro doesn't come with the compiler. You'll need the sdk for this which is only available on a computer.
 
Back
Top Bottom