I want to integrate a c language compiler in to java application to compile c sources without file creation (Like Java Compiler Api). Is there any c compiler that has entirely written in java?
2 Answers
You can check this link from Google Code C compiler written in Java
and say congratz to the developer :) -it's not me :p-
Another option is this one: JCPP
ANTRL has a grammar for C. The problem of generating assembly code for a particular platform isn't solved for you, but you can walk the AST and emit the instructions provided you know what they should be.
10 Comments
Paul Cager
Parsing the source into an AST is usually the easiest bit of a compiler. Semantic analysis and code generation would be a massive task.
duffymo
I agree with that, Paul. Code generation is platform-specific and difficult.
duffymo
By definition, a C compiler is platform dependent, because the generated assembly code is tied to the platform. ANTLR won't help with assembly code generation, but neither will anything else. This is a difficult problem if you understand it.
duffymo
Your platform independent conclusion is based on the assumption "consider the x86 to be your VM-language". I didn't make the assumption when I said that machine code was tied to the platform. I realize that C the language is independent of the machine code that is generated for it. I'm talking about the second step - machine code generation - after the C standard grammar has been used to parse the source into an AST.
Ira Baxter
No, you don't have to write machine code; the interpreter can do machine specific I/O, memory access, and OS calls. Agreed, if you want to use C for arbitrary low-level metal, you have to be clear about what the metal is. OP is pretty unclear about his goal here.
|