j2py with stratego/jafa-front

20 views
Skip to first unread message

toka

unread,
Jun 14, 2010, 8:11:44 AM6/14/10
to java2python-discuss
Hello.

I was looking for some java2python framework to do translations for
the pyjamas (http://pyjs.org) project.

I have got some code running, but a lot of features are still missing.

Could you imagine, that the efforts could be joined in some way ?

stratego is a language translation toolset. java-front brings parsing
of java into easily readable aterm format.

I wrote a aterm parser for python, some transformation scripts from
AST in aterm to AST in
python and hacked the pp-java prettiprinter to produce python output
(as pp-java2py).

You will find the sources at http://github.com/thoka/java2python

In principle, I find the approach to join multiple steps to do
transformations very appealing.

A transformation looks like

cat src.java | parser | transform1 | transform2 | topyrenderer >
src.py


I will dig into java2python code to understand your approach.

Which of the branches should I concentrate on ?


Second question: is this the right place to talk about java 2 python
translation in general ?

--Thomas Kalka





Troy Melhase

unread,
Jun 15, 2010, 4:12:25 PM6/15/10
to java2pyth...@googlegroups.com
> Hello.

Hello Thomas,


> I was looking for some java2python framework to do translations for
> the pyjamas (http://pyjs.org) project.
>
> I have got some code running, but a lot of features are still missing.

That sounds familiar. :)

> Could you imagine, that the efforts could be joined in some way ?

I don't know. The approaches look very different.

> stratego is a language translation toolset. java-front brings parsing
> of java into easily readable aterm format.

Thank you for pointing out stratego; I've never seen it until now.

> In principle, I find the approach to join multiple steps to do
> transformations very appealing.
>
> A transformation looks like
>
>  cat src.java | parser | transform1 | transform2 | topyrenderer >
> src.py

That is nice! I wish I had thought of pipelining the transformations like that.

What do each of the transformations accomplish? I've looked over some
of the docs and your examples, but I'm not certain what each one of
them does at each stage.

Also, the strategy files seem very specific to the sources you're
translating. Is this true? To write a tool to translate java into
python, what would you need to write beyond the grammar and these
translations? (I'm assuming you're writing the entire grammar).


> I will dig into java2python code to understand your approach.

The approach is to rely on antlr as much as possible. In the current
versions (the 0.4 branch), as the parser walks the java source file,
we invoke various functions to construct an intermediate python
object. When the walker is complete, we ask the python object to
write itself to output. At various points in the
walking/building/writing, we apply transformations in the form of
lookup replacements and regular expressions. It's not very
computer-science-y, it's mostly string-y.

> Which of the branches should I concentrate on ?

I'm tinkering these days on the 0.4 branch. I've got basic blocks
working and committed.


> Second question: is this the right place to talk about java 2 python
> translation in general ?

Yes, this would be the place. Or you can mail me directly.

troy

lkcl

unread,
Jun 15, 2010, 5:20:48 PM6/15/10
to java2python-discuss


On Jun 15, 8:12 pm, Troy Melhase <troy.melh...@gmail.com> wrote:
> >  cat src.java | parser | transform1 | transform2 | topyrenderer >
> > src.py
>
> That is nice!  I wish I had thought of pipelining the transformations like that.
>
> What do each of the transformations accomplish?

we figured it would be neater to simply do one task at a time, even
though overall this would result initially in worse performance.

so, one script would do moving of comments to end-of-line, because
otherwise the following code:

if (x && y/* maybe */ ) {
}

would get translated to:
if (x and y # maybe ):

which is obviously a mistake!

also, by using the pipelines, GWT-specific transforms into pyjamas-
specific code can be performed by pyjamas developers but _not_ forced
onto other users.

so, one of the transforms will understand import
com.google.gwt.user.client.ui.RootPanel and translate that into "from
pyjamas.ui.RootPanel import RootPanel" - and do nothing else.

l.
Reply all
Reply to author
Forward
0 new messages