All Projects → jarble → Transpiler

jarble / Transpiler

Licence: mit
A universal translator for programming languages

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Transpiler

Headache
Programming Language that compiles to 8 Bit Brainfuck
Stars: ✭ 59 (-79.79%)
Mutual labels:  transpiler
go2hx
Go -> Haxe -> JS Java C# C++ C Python Lua
Stars: ✭ 49 (-83.22%)
Mutual labels:  transpiler
idealingua-v1
IdeaLingua RPC for Scala, TypeScript, C#, Go
Stars: ✭ 13 (-95.55%)
Mutual labels:  transpiler
bck2brwsr
Bck2Brwsr VM to transpile Java bytecode to JavaScript
Stars: ✭ 93 (-68.15%)
Mutual labels:  transpiler
rewrite-imports
Rewrite `import` statements as `require()`s; via RegExp
Stars: ✭ 31 (-89.38%)
Mutual labels:  transpiler
go2cpp
Go to C++20 transpiler
Stars: ✭ 51 (-82.53%)
Mutual labels:  transpiler
sugartex
SugarTeX is a more readable LaTeX language extension and transcompiler to LaTeX. Fast Unicode autocomplete in Atom editor via https://github.com/kiwi0fruit/atom-sugartex-completions
Stars: ✭ 74 (-74.66%)
Mutual labels:  transpiler
Js2php
JavaScript (ES6) to PHP source-to-source transpiler.
Stars: ✭ 290 (-0.68%)
Mutual labels:  transpiler
BashClass
BashClass is an Object Oriented Programming language that compiles to BASH 4.4
Stars: ✭ 40 (-86.3%)
Mutual labels:  transpiler
wxml-transpiler
Port of wcc.exe to JavaScript. wxml 文件编译器 --- 里面有很多无用代码,有空再整理下
Stars: ✭ 21 (-92.81%)
Mutual labels:  transpiler
qaffeine
Decaffeinate your JS-powered CSS stylesheets
Stars: ✭ 22 (-92.47%)
Mutual labels:  transpiler
grizzly
A Python-to-SQL transpiler as replacement for Python Pandas
Stars: ✭ 27 (-90.75%)
Mutual labels:  transpiler
grumpy
Grumpy is a Python to Go source code transcompiler and runtime.
Stars: ✭ 378 (+29.45%)
Mutual labels:  transpiler
js-slang
Implementations of the Source languages, which are small sublanguages of JavaScript designed for SICP JS
Stars: ✭ 41 (-85.96%)
Mutual labels:  transpiler
Il2c
IL2C - A translator for ECMA-335 CIL/MSIL to C language.
Stars: ✭ 270 (-7.53%)
Mutual labels:  transpiler
escapin
Escapin is a JS/TS transpiler for escaping from complicated usage of cloud services and APIs
Stars: ✭ 20 (-93.15%)
Mutual labels:  transpiler
Go2SourcePawn
Go2SourcePawn is a transpiler that transforms a subset of Golang-like code to equivalent SourcePawn.
Stars: ✭ 13 (-95.55%)
Mutual labels:  transpiler
Pytocs
Converts Python source to C#
Stars: ✭ 288 (-1.37%)
Mutual labels:  transpiler
Go On Rails
🚄 Use Rails to Develop or Generate a Golang Application.
Stars: ✭ 275 (-5.82%)
Mutual labels:  transpiler
Yuescript
A Moonscript dialect compiles to Lua.
Stars: ✭ 172 (-41.1%)
Mutual labels:  transpiler

Build Status

Universal-transpiler

Universal-transpiler is a source-to-source compiler that translates a small subset of several programming languages into several others. It is also able to translate several metasyntax notations, such as EBNF and ABNF.

Universal-transpiler was written as an experimental "proof-of-concept," so it can only translate relatively simple programs. The translation is not always 100% accurate, but I hope it will still be useful.

The online version of this translator is written in JavaScript, but an experimental version is also being written in Prolog.

A major goal of this project is to translate TypeScript and JavaScript to other languages that compile to C or native code. For example, it's possible to translate a subset of TypeScript to Zig:

var a = {a1:1,b:2};

var b = function(a1:number,b:number):number{
return a + b;
};

This is the compiler's output:

var a=.{.a1=1,.b=2};
var b=struct{fn function(a1:f64,b:f64)f64{
    return a+b;}}.function;

How to use the online translator

This translator can convert many languages into many others:

Constraint programming and automated reasoning

Universal-transpiler is able to generate code in several constraint programming languages and computer algebra systems, including MiniZinc, Maxima, Sage, Algebrite, and Axiom. Some languages can also be translated into the SMT-LIB, TPTP, Coq, Isabelle/HOL, and alt-ergo languages for automated theorem proving. As an experimental feature, it also converts a subset of Prolog into the PDDL automated planning language.

Similarly, it can translate constraint handing rules from Prolog into CLIPS and vice-versa.

Ontology languages

Universal-transpiler can also translate programming languages into the KIF ontology language.

Generating parsers with universal-transpiler

Universal-transpiler can also translate various grammar notations, such as jison, marpa, peg.js, and nearley.

How to use the Prolog translator

The Prolog translator is still unfinished and experimental. You can 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;}",javascript,lua,X),
	atom_chars(Y,X),
	writeln(Y).

How to extend the Prolog translator

A limited number of translation rules are provided here, but you can easily add your own rules to 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,")"),
    ]).

Other planned features:

  • Add a translator for lens languages such as Augeas and Boomerang
  • Simplify and refactor the code generator using string interpolation
  • Converting SQL to Linq and vice-versa
  • Simultaneous editing of two programming languages in two text areas
  • Translate list comprehensions from other languages into Prolog.
  • Try to translate markup languages, similar to Pandoc.
  • Try to convert SVG into other vector graphics formats
  • Try to convert X3D into other vector graphics formats

Similar projects

There are several other source-to-source compilers and code generators that are similar to this one.

JTransc compiles Java, Kotlin, and Scala into several other programming languages. Pandoc is a universal document converter

This universal code generator is one example.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].