Ruby to Python translator

Discussion in 'Ruby' started by Aureliano Calvo, Nov 15, 2007.

  1. Hi all!
    I'm thinking about implementing a ruby to python translator (this is a
    program that takes a ruby program and generates its equivalent program
    in python). In order to get started, I would like to know if there is
    a ruby grammar implemented in python or with another tool.

    The final idea for the project would be to run ruby code on the OLPC.

    Can you give me any pointers?

    Aureliano.
     
    Aureliano Calvo, Nov 15, 2007
    #1
    1. Advertising

  2. Aureliano Calvo

    Ryan Davis Guest

    On Nov 15, 2007, at 10:37 , Aureliano Calvo wrote:

    > I'm thinking about implementing a ruby to python translator (this is a
    > program that takes a ruby program and generates its equivalent program
    > in python). In order to get started, I would like to know if there is
    > a ruby grammar implemented in python or with another tool.


    None that I know of outside of ruby.

    > The final idea for the project would be to run ruby code on the OLPC.


    Why not run ruby on OLPC? Just to avoid the extra install?
     
    Ryan Davis, Nov 15, 2007
    #2
    1. Advertising

  3. Aureliano Calvo

    Markus Liedl Guest

    On Nov 15, 7:37 pm, Aureliano Calvo <> wrote:
    > Hi all!
    > I'm thinking about implementing a ruby to python translator (this is a
    > program that takes a ruby program and generates its equivalent program
    > in python). In order to get started, I would like to know if there is
    > a ruby grammar implemented in python or with another tool.


    You might have a look at the "Ruby top down Grammar" project. It is a
    hosting language neutral Ruby grammar. You might translate that
    grammar
    to a Python recursive descent parser or interprete the grammar from
    some
    Python code. If you know Python well that should be doable in a few
    days
    time. Be warned that you would be the first client of this grammar.

    > Aureliano.
     
    Markus Liedl, Nov 16, 2007
    #3
  4. Aureliano Calvo schrieb:
    > Hi all!
    > I'm thinking about implementing a ruby to python translator (this is a
    > program that takes a ruby program and generates its equivalent program
    > in python). In order to get started, I would like to know if there is
    > a ruby grammar implemented in python or with another tool.
    >
    > The final idea for the project would be to run ruby code on the OLPC.
    >
    > Can you give me any pointers?


    I'm translating Ruby to Javascript and use ParseTree for that. Python is a
    little less dynamic than Ruby, so for example AFAIK Python doesn't execute
    module-level code when it is loaded as Ruby does. That means that you can't
    simply convert Ruby to Python code 1:1. What I am doing with RubyJS (my Ruby to
    Javascript compiler) is to first evaluate the Ruby code (all meta-programming
    stuff is going on here) and then compile each class to Javascript. This is very
    powerful.

    It should be easier to compile Ruby to Python than it is for compiling Ruby to
    Javascript. But I'd be more interested in compiling Python to Ruby, which should
    be even easier.

    Regards,

    Michael
     
    Michael Neumann, Nov 16, 2007
    #4
  5. On Nov 16, 2007 8:57 AM, Michael Neumann <> wrote:

    > It should be easier to compile Ruby to Python than it is for compiling Ruby to
    > Javascript.


    From what I've heard and seen of Javascript, I'm not sure that the
    opposite isn't true.

    Javascript gets much less credit than it deserves.

    --
    Rick DeNatale

    My blog on Ruby
    http://talklikeaduck.denhaven2.com/
     
    Rick DeNatale, Nov 16, 2007
    #5
  6. Aureliano Calvo

    Mark Shroyer Guest

    On 2007-11-16, Michael Neumann <> wrote:
    > I'm translating Ruby to Javascript and use ParseTree for that.
    > Python is a little less dynamic than Ruby, so for example AFAIK
    > Python doesn't execute module-level code when it is loaded as Ruby
    > does.


    There's a pretty good chance I'm misinterpreting what you mean by
    this; however,

    [sed:~] mshroyer$ echo '
    > class SomeClass:
    > def greet(self):
    > print "Hello there..."
    >
    > c = SomeClass()
    > c.greet()
    > ' > mymodule.py

    [sed:~] mshroyer$ python
    Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
    [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
    Type "help", "copyright", "credits" or "license" for more
    information.
    >>> import mymodule

    Hello there...
    >>>


    --
    Mark Shroyer
    http://markshroyer.com/
     
    Mark Shroyer, Nov 17, 2007
    #6
  7. Rick DeNatale schrieb:
    > On Nov 16, 2007 8:57 AM, Michael Neumann <> wrote:
    >
    >> It should be easier to compile Ruby to Python than it is for compiling Ruby to
    >> Javascript.

    >
    > From what I've heard and seen of Javascript, I'm not sure that the
    > opposite isn't true.


    IMHO Python has a much better underlying model, just take Javascript "null"
    special values. They are not objects! This makes it harder to compile from an
    "everything is an object language" to Javascript. Just one example :)

    Regards,

    Michael
     
    Michael Neumann, Nov 18, 2007
    #7
  8. > > Hi all!
    > > I'm thinking about implementing a ruby to python translator (this is a
    > > program that takes a ruby program and generates its equivalent program
    > > in python). In order to get started, I would like to know if there is
    > > a ruby grammar implemented in python or with another tool.

    >
    > You might have a look at the "Ruby top down Grammar" project. It is a
    > hosting language neutral Ruby grammar. You might translate that
    > grammar
    > to a Python recursive descent parser or interprete the grammar from
    > some
    > Python code. If you know Python well that should be doable in a few
    > days
    > time. Be warned that you would be the first client of this grammar.


    That's what I was looking for, tanks.
     
    Aureliano Calvo, Nov 19, 2007
    #8
  9. > > I'm thinking about implementing a ruby to python translator (this is a
    > > program that takes a ruby program and generates its equivalent program
    > > in python). In order to get started, I would like to know if there is
    > > a ruby grammar implemented in python or with another tool.

    >
    > None that I know of outside of ruby.
    >
    > > The final idea for the project would be to run ruby code on the OLPC.

    >
    > Why not run ruby on OLPC? Just to avoid the extra install?


    Yeah! But it's a lot more important that seems like an entertaining project.
     
    Aureliano Calvo, Nov 19, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Engineer
    Replies:
    6
    Views:
    649
    Jeremy Bowers
    May 1, 2005
  2. Replies:
    0
    Views:
    458
  3. rogerdpack

    ruby -> python translator exists?

    rogerdpack, Dec 27, 2008, in forum: Python
    Replies:
    3
    Views:
    388
    rogerdpack
    Dec 27, 2008
  4. Gully Foyle
    Replies:
    4
    Views:
    463
    Frank Mitchell
    Jul 25, 2004
  5. Replies:
    4
    Views:
    196
    Erik Hollensbe
    May 2, 2006
Loading...

Share This Page