Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "transpiler"

Title:A universal translator for programming languages
Rating:Not rated. Create the first rating!
Latest version:0.1
SHA1 sum:feba96c898365107f24e690cbf0ad9b30e6ede94
Author:Anderson Green <jarble@gmail.com>
Maintainer:Anderson Green <jarble@gmail.com>
Packager:Anderson Green <jarble@gmail.com>
Home page:https://github.com/jarble/transpiler/
Download URL:https://github.com/jarble/transpiler/archive/v0.1.zip

Reviews

No reviews. Create the first review!.

Details by download location

VersionSHA1#DownloadsURL
0.12b036e9d6964c90d1e2281db8db4e742727353932https://github.com/jarble/transpiler/archive/v0.1.zip
873fb8e46d8a3d2454d49aa54677fdd9903886fe4https://github.com/jarble/transpiler.git
3f13033ca4399d797f637b09942ccc70bb9eca743https://github.com/jarble/transpiler.git
feba96c898365107f24e690cbf0ad9b30e6ede943https://github.com/jarble/transpiler.git
989a84b41a23db0ba3680893ce2aeac45f6b3b3144https://github.com/jarble/transpiler/archive/v0.1.zip
426d9f6eb52697a6e9387337eb085992bb77a3e41https://github.com/jarble/transpiler.git
2fd47e8056c688821f0d56761ec058a298f6be861https://github.com/jarble/transpiler.git
5b9cbdf976108d5b3e5260ad992f6b88c850151d1https://github.com/jarble/transpiler.git
30421ac3a32d55f235e89723517af0dbc5e7ff452https://github.com/jarble/transpiler.git
ba7c537d1c36552e4cf2896c832c12560a4cdcb21https://github.com/jarble/transpiler.git
807b9b25453c3e33b1668c05554d222685e3607a1https://github.com/jarble/transpiler.git
177363303931bbd3353a95f06e29827d0a265d761https://github.com/jarble/transpiler.git
e29323955d6264605ceeeea2deb68c63d6ed48c72https://github.com/jarble/transpiler.git
bd753575241c231faaaa04b0b5b92dc0811289bf11https://github.com/jarble/transpiler.git
a5011afa3876b304bbca685975defd78a325eb551https://github.com/jarble/transpiler.git
336467a68f7611b3a68ac5b7ef36a0dac3740bf41https://github.com/jarble/transpiler.git
9e2a5d6eac13e8a77fecbb8b03d5356df0fc94771https://github.com/jarble/transpiler.git
5f0bed7ac03c9a594d10510543d608b5f345d7d93https://github.com/jarble/transpiler.git
a9b7e7c42876b98f55e789a5523993eb295c4a281https://github.com/jarble/transpiler.git
1df6be304f5351723f199b7ed55c8b81f416b9e65https://github.com/jarble/transpiler.git
11c9e6806401c840759acf9918c402ed8b99296e7https://github.com/jarble/transpiler.git
2a1c90e2b7a0ba69ca577b9af9230eb5eec1003712https://github.com/jarble/transpiler.git
b7e263292ac19042d0f07df84a44f2f02b100ad78https://github.com/jarble/transpiler.git

Universal-transpiler

Universal-transpiler is a source-to-source compiler that translates a subset of most programming languages into several others.

The original version of this translator was written in JavaScript, but [a better version has been written in Prolog](universal-transpiler.pl).

This is some JavaScript code:

function add(a,b){
        var g = [3,4,5];
        return a+b+(g[0])+(g.length);
}

function divide(a,b){
        return a/b;
}

and this is the Java code that it generates:

public static int add(int a,int b){
        int[] g={3,4,5};
        return a+b+(g[0])+(g.length);
}

public static int divide(int a,int b){
        return a/b;
}

#How to use this translator

Install the package by typing pack-install(transpiler) in the SWI-Prolog console. Now, you can use the translator to convert JavaScript source code into Lua:

:- use_module(library(transpiler)).
:- set_prolog_flag(double_quotes,chars).
:- initialization(main).

main :- translate('function add(a,b){return a + b;}',lua,X),writeln(X).

#How to extend the translator

A limited number of translation rules are provided here, but you can easily add your own rules to universal-transpiler.pl. This is a simplified version of one of its translation rules, implementing the sine function:

%The type of this expression is double.
parentheses_expr(Data,double,sin(Var1_)) -->
{
                %The parameter of the sine function can be an integer or double.
                Var1 = expr(Data,double,Var1_)
        },
langs_to_output(Data,sin,[
['java','javascript']:
        ("Math",ws,".",ws,"sin",ws,"(",ws,Var1,ws,")"),
['lua','python']:
        ("math",python_ws,".",python_ws,"sin",python_ws,"(",python_ws,Var1,python_ws,")"),
]).

Contents of pack "transpiler"

Pack contains 14 files holding a total of 1.0M bytes.