www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - j2d - translating Java to D with the language machine

reply Peri Hankey <mpah thegreen.co.uk> writes:
Hello

Following an exchange of emails with Brad Anderson I have adapted my 
d-to-d translator to translate from java to D. It's at a very early 
stage (I started a couple of days ago). It seems to me that the first 
thing to do is to apply it to the gnu classpath sources.

Results so far:

               j2d ok? gdc syntax ok? gdc compile?  source lines
   java.lang   y       y              n             33871
   java.util   y       y              n             56636
   java.io     y       y              n             23187

This is quick and dirty so far: the code is probably wrong in many 
places, and mapping java classes and run-time class information may be 
tricky - I'm sure many of you will have already thought about this. At 
present compilation fails because modules are not being found, but when 
they are found there will be a different crop of incompatible 
this-that-the-other errors. Also the java.lang modules need to be 
automatically included.

So there is a great deal to do. The sources (about 700 rules, 1100 
lines) are in SVN at dsource - it's easiest to start at

    http://languagemachine.sourceforge.net/j2d.html

and follow the link. I am developing on Linux, and this is definitely a 
project that needs shared libraries. The easiest way to join the chase 
is to use:

* the language machine (required)
* gdc (0.17) - for shared libraries on Linux
* gnu make - (or roll your own build tools)
* gnu classpath sources: http://www.gnu.org/software/classpath/

Suggestions, feedback, assistance all welcome.

Peri

-- 
Peri Hankey                               mpah thegreen.co.uk
http://languagemachine.sourceforge.net - The language machine
Mar 27 2006
parent reply "Walter Bright" <newshound digitalmars.com> writes:
"Peri Hankey" <mpah thegreen.co.uk> wrote in message 
news:e09ta6$2rco$1 digitaldaemon.com...
 Following an exchange of emails with Brad Anderson I have adapted my 
 d-to-d translator to translate from java to D. It's at a very early stage 
 (I started a couple of days ago). It seems to me that the first thing to 
 do is to apply it to the gnu classpath sources.
What are you using for a lexer?
Mar 27 2006
parent Brad Anderson <brad dsource.dot.org> writes:
Walter Bright wrote:
 "Peri Hankey" <mpah thegreen.co.uk> wrote in message 
 news:e09ta6$2rco$1 digitaldaemon.com...
 Following an exchange of emails with Brad Anderson I have adapted my 
 d-to-d translator to translate from java to D. It's at a very early stage 
 (I started a couple of days ago). It seems to me that the first thing to 
 do is to apply it to the gnu classpath sources.
What are you using for a lexer?
Walter, I just started with The Language Machine, and am no expert by any means, but I'll give it a shot... The LM is kind of a lexer and parser rolled into one. http://languagemachine.sourceforge.net/ is a good intro, as well as the paradigm shift page. Rules like: [a-z_A-Z] % { { repeat [a-zA-Z_0-9] % } toSym:X } <- identifier symbol :X ; identify that any letter or underscore, followed by zero or more letter/underscores is stored in a symbol X, and the right-hand side of the rule says these are symbols (tokens in a normal lexer). Later on, rules like: "instanceof" type :B <- op opnd:{ ft :"ty" :A :B }; tell us that this java 'instanceof' symbol becomes a 'ft' in the intermediate representation. These are the Java to X frontend rules contained here: http://www.dsource.org/projects/languagemachine/browser/trunk/languagemachine/src/j2d/j2xfe.lmn (X being the intermediate representation). Then an X to D backend set of rules is used to take that 'ft' and make it into a 'D instanceof', if there is any difference between the two languages, which there is in this case. The rule in the backend turns it into D code: ft :F :A :B <- code - "(cast(" B ")" A ")"; The D backend can be found here: http://www.dsource.org/projects/languagemachine/browser/trunk/languagemachine/src/j2d/x2dbe.lmn It's a little bit like Scott Sanders' Molt project which hacked the Jikes compiler into emitting an XML intermediate representation of the Java code and XSLT was used to take the XML doc and transform it into D. hth, BA P.S. Peri, how'd I do?
Mar 27 2006