10

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 2

6

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

Sign up to request clarification or add additional context in comments.

2 Comments

Your link to github C compiler is not pointing to github, and the link is broken.
Fixed, thanks for the notification! (It's been a long time)
1

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

Parsing the source into an AST is usually the easiest bit of a compiler. Semantic analysis and code generation would be a massive task.
I agree with that, Paul. Code generation is platform-specific and difficult.
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.
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.
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.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.