How to encode source code converter from python to ruby?

My teacher told me that if I want to get the best class in our programming class, I have to code a simple source code converter.

Python to Ruby (the easiest one he said)

Now my question is for you: how difficult is it to code a simple python to ruby ​​source code converter? (It should convert file control, control messages, etc.)

Do you have any tips for me?

What language should I use to encode the converter (C #, Python or Ruby)?

+4
source share
8 answers

I think your fibring teacher is quite complicated. This is equivalent to writing a compiler / interpreter. I don’t know how much time you have for this project, but you usually look at a few man-years of work.

+13
source

There is a name for a program that converts one type of code to another. It is called a compiler (even if the target language is not machine or byte code).

Compilers are not the easiest part of computer science, and this is a project that, if it were something more than a toy implementation of the converter, would be a large-scale project. Of course, this is more than usual for a class project in most university courses. (Even many / most compiler courses have fairly modest project assignments.

What about the language? Well, whichever you know best, this is probably the answer. Although, if you want to learn something new, Haskell will be a good choice, with its functions matching the pattern. (Disclaimer: I'm new to haskell.) (Yacc can also be used if you are really serious about getting into compilers.)

You will also want to consult: A dragon compiler book that is worth exploring, even if you do not plan to write compilers.

+2
source

It's as simple as coming up with smart enough regular expressions that correctly translate syntax.
The syntax of Ruby and python is close enough that it is not very complicated.
You may need to do some extra work to rewrite material that you have in python that, for example, does not exist in ruby, for example, to define a listing.

0
source

The first simple may mean that it does not care about all the valid Python semantics, but only a subset of this.

The first thing I could get is a copy of the dragon book, which you can find in any university library. The second thing I would like to do is get a copy of Python syntax and semantics.

0
source

language should not matter. Choose the one you like best in the rows.

tips wise I would use a dictionary / look -up array for keywords. The hardest part will deal with a space in python

0
source

It looks like your teacher is a little practical prankster!

0
source

The hardest part is maintaining semantics.

How do you feel about metaclass assignments, or function decorators, or profitability-based generators when switching to Ruby? I have no Ruby experience, so I don’t know what is supported directly.

0
source

It would be quite simple to write a converter between Brainf *** and C. I am sure it is much lower than what you need to do (I guess something that teaches you about parsing context-free grammars), but it would be very easy to do.

0
source

All Articles