Project Idea: Universal Code Converter

User projects written in or related to FreeBASIC.
duke4e
Posts: 717
Joined: Dec 04, 2005 0:16
Location: Varazdin, Croatia, Europe
Contact:

Project Idea: Universal Code Converter

Postby duke4e » Jun 24, 2006 18:21

I have an idea to make a really nice and useful tool, so before I start making it, I whould like to hear your input about the idea, and to tell me if there is already a similar software, and if someone whould like to help me...

The idea is pretty simple: make a program which could translate code from one programming language to another. AFAIK there are already some programs which translate from some languages to another, but my idea is to make a program which could have an extendeble database and support as many languages as possible.

To make a perfect converter whould be a nearly impossible task, so my idea is that converter converts as much code as it can, and just comment out the code which can't be translated. What to do with the unconverted code whould be a task for the user who converted the code.

I think that my idea is pretty useful, cause more than 50% of any code (in any language) are just stuff like loops/if-then-else/simple math/etc... So instead of 100% conversion, the program whould convert pretty big part of the code, and so it whould greatly reduce the time of manual conversion. I think that is's easyer that machine translates some code and leave you to translate the other part, instead of you translating the whole code.
redcrab
Posts: 619
Joined: Feb 07, 2006 15:29
Location: France / Luxemburg
Contact:

Postby redcrab » Jun 24, 2006 18:37

But it's already exist...
Combination of an Lexical and Syntaxic analysers..
Convertion of Language L1 to Language L2

Unix : Lexx & Yacc
Gnu : Flex & Bison

I'm poor cultured in this domain ... But I think that V1ctor is a master with this...

EDIT : From code written with L1 create a internal tree then with this tree generate a new code in language L2... if some part are missunderstood may they put them AS is as comment into language L2..


Hope you get fun !
Last edited by redcrab on Jun 24, 2006 18:42, edited 2 times in total.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Jun 24, 2006 18:38

But has it been made in FreeBASIC yet? ^_~;;
redcrab
Posts: 619
Joined: Feb 07, 2006 15:29
Location: France / Luxemburg
Contact:

Postby redcrab » Jun 24, 2006 18:46

Pitchard wrote:But has it been made in FreeBASIC yet? ^_~;;

Why not if Flex and Bison could generate FB code ;)
duke4e
Posts: 717
Joined: Dec 04, 2005 0:16
Location: Varazdin, Croatia, Europe
Contact:

Postby duke4e » Jun 24, 2006 19:00

After a little googling i think that flex and bison can only convert into c code. I think i'm wrong, but maybe not...

My idea for converter whould be to break each line into seperate words, then look into input dictionary (which whould recognize the form/rules of commands) and then convert them to another form using rules from output dictionary. Every form which could not be recognized on input/output dictionary whould be commented out.

The input and output dictionarys whould be the same file. Here are few ideas for dictionarys:
C++
C++ with SDL
C++ with Allegro
Blitzmax
FreeBASIC
FreeBASIC with SDL
FreeBASIC with Allegro

So, you could translate C++ with SDL into C++ with Allegro, or any other combination. Also, dictionarys whould be extendable, and users could create new dictionarys, adding more and more support for programming languages...

Simple, but should work...
duke4e
Posts: 717
Joined: Dec 04, 2005 0:16
Location: Varazdin, Croatia, Europe
Contact:

Postby duke4e » Jun 25, 2006 2:32

And so it begins...

http://fileanchor.com/38184-d
It's not much, but it fixes "messy" code and then saves each word into array. My next task is to make 2 simple/small databases (one with FreeBASIC syntax and one with C++ syntax) and to make code which can convert between them.

Databases will be constructed similar to this:
FB database: "for var1 = var2 to var3 step var4"
C++ database: "for var1 = var2; var1 <= var3; var1 = var1 + var4"

This is just a small example and I know things will get nasty, but my plan is to make converter/conversion as simple as possible.

Please give me your comments! Also, any help whould be more than welcome! It whould be great if people whould help me, and make this project a community project.
Deleter
Posts: 975
Joined: Jun 22, 2005 22:33

Postby Deleter » Jun 25, 2006 4:47

what about something like:

Code: Select all

for(var1=0,var2=6 ; var1 > var2 ; var1+=2, var2++) {
    //code
}


Will you just convert that to a loop? And if you have such a thing:

Code: Select all

var1=0
var2=6
do
    var1+=2
    var2+=1
    'code
loop until var1 > var 2


would it convert it to the tider code or is that left to the user to do?

I think a translator would be great...but I wonder if it could ever be completely "fluent" in all the langs. What I think would be neat would be if you made a meta language that could export to any language of your choosing...;)
idcarlos
Posts: 3
Joined: Sep 25, 2005 18:26

Postby idcarlos » Jun 25, 2006 9:57

Hi.

A universal converter it's to hard for me :)
I'm trying something more easy, a GUI converter from Visual Basic to GLADE.
http://www.freebasic.net/forum/viewtopi ... 9772#39772

What I think would be neat would be if you made a meta language that could export to any language of your choosing...;)


I think that this is the correct way. Translate to a meta language (GLADE to GUI interface) and other programmer work with this meta-language like a plugin.

Glade files can be used with many languages, and off course with FB.

Un saludo
Carlos Garcés
Lutz Ifer
Posts: 34
Joined: Mar 16, 2006 10:05

Postby Lutz Ifer » Jun 25, 2006 10:17

I don't think, that its just parsing the trees and build the "foreign language" code from that:

Every language has some kind of special things, that can't be translated directly into other languages. I translated some c-code (for a plugin) to fb some time ago. 80% of that code handled allocating, deallocating and reallocating the strings the plugin got from the program. 50 loc in c became less than 10 loc in fb - just because i didn't had to take care about the fixed-len zstrings, but use strings and strptr().
Imagine what an automated translator would have done with that, and vice versa, converting the fb-code to c.
jevans4949
Posts: 1156
Joined: May 08, 2006 21:58
Location: Crewe, England

Postby jevans4949 » Jun 27, 2006 0:28

blahboybang
Posts: 385
Joined: Oct 16, 2005 0:15
Location: USA
Contact:

Postby blahboybang » Jun 27, 2006 3:28

@jevans4949
Hehe, Nice one.

@all
EAT THAT, DISCOURAGERS!
jevans4949
Posts: 1156
Joined: May 08, 2006 21:58
Location: Crewe, England

Postby jevans4949 » Jun 27, 2006 8:16

:-)

Actually, I had started looking for an alternative version of this which I saw once years ago, which ended up " ... And he found he couldn't do it".

Which will apply I'm not sure. In my experience, the output of source-code generators which I've seen is often not very pretty, even if it does correspond to the original.
Rudiger
Posts: 93
Joined: Mar 17, 2006 3:54
Location: florida, massachusetts, southwest airlines
Contact:

Narrow Scope

Postby Rudiger » Jul 15, 2006 1:25

My suggestion is that for this project to ever get off the ground, it would be wise to narrow the scope to a meta-language to Freebasic converter, since the one common denominator here is an interest in Freebasic. The front-end visual basic, c, python, etc. to meta-language portions can then be driven by demand. Ideally, the project would have logical divisons for data item definitions, function and procedure definitions, Input/Output controls, and processing logic. This would enabe different individuals to develop different components.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 6 guests