Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Java
Dear, Member
 
I have some question to asking you:
How to build a compiler in C to converting to Java?
 
The condition of program is
 
1.input your C source code into Compiler
2.Converting and to show all of character appears along with which type, such as
 
Reserve Word, Token is ...
 
3. Output be show in Java code
 
By the way I've searching the related article in Google they' say it possible but not full option , I really to know your opinions How it can prove some part it working ?
 
Please, give me an advice
 
Email <Removed>
If you have some C source code to converting to Java Code
 
Thanks.
Posted 16-Jan-13 8:07am
Tiensin402
Edited 16-Jan-13 8:22am
v2
Comments
Sergey Alexandrovich Kryukov at 16-Jan-13 14:15pm
   
Why? I don't think it can make sense...
—SA
André Kraak at 16-Jan-13 14:23pm
   
You should not post your e-mail address on a public forum, unless you want to test your spam filter.
If someone comments on or answer your question you will be notified by an e-mail.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is pretty difficult because C is of much lower level compared to Java. I don't think such work would make any sense. There are products which can be used to compile code written in different languages to Java machine. I used Ada; but it could also be C#, Object-oriented dialect of Pascal, Python, PHP, and more. Please see:
http://en.wikipedia.org/wiki/Java_virtual_machine#JVM_languages[^].
 
Adding C to this list can hardly do something good. The languages good to target JVM are usually object-oriented, or have close capabilities. You need something to represent classes, members of classes and related encapsulation. This is not about C.
 
And the term "converting to Java code" sound just ridiculous. What could you possibly mean by that? Listen for a good friendly advice: just forget it.
 
—SA
  Permalink  
Comments
Espen Harlinn at 16-Jan-13 16:00pm
   
Good points - If OP really want interpreted C he can try interfacing with root/cint.
Sergey Alexandrovich Kryukov at 16-Jan-13 16:09pm
   
Thank you, Espen.
I have an idea on what you are talking about, but... ah, I can see you answer.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

It could be made to work, but it's definitely nontrivial.
 
ROOT/CINT[^] will give you some idea about what's required to make something like this really work - but then I guess it will make more sense just to interface with CINT using JNI.
 
Best regards
Espen Harlinn
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 16-Jan-13 16:10pm
   
Good point, if it makes sense at all; but it's a good reply, a 5.
—SA
Espen Harlinn at 17-Jan-13 16:48pm
   
Thank you, Sergey :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 853
1 OriginalGriff 410
2 CPallini 275
3 George Jonsson 226
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,482
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100