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.
1: The Lua Sources. 2: A C compiler - cc/gcc/g for Unix, and Visual C for Windows. Other compilers should under Windows, basically any C compiler - I will cover compiling under Windows at the end of the toturial. This tutorial will work under any OS which has a C compiler, and which Lua has compiled succesfully on.
- By using LuCa, the programmer need not use C API functions; the programmer can directly write Lua-like code, which is much clearer than C code that uses many API calls. We have implemented a LuCa processor as a translator from LuCa code into C code that calls appropriate C API functions.
- Apr 07, 2020 CTranslate is a C implementation of OpenNMT's translate.lua script with no LuaTorch dependencies. It facilitates the use of OpenNMT models in existing products and on various platforms using Eigen as a backend. CTranslate provides optimized CPU translation and optionally offloads matrix multiplication on a CUDA-compatible device using cuBLAS.
- CTranslate2 is a fast inference engine for OpenNMT-py and OpenNMT-tf models supporting both CPU and GPU execution. The goal is to provide comprehensive inference features and be the most efficient and cost-effective solution to deploy standard neural machine translation systems such as Transformer models.
Some supported features
- Generics and templates (in several languages)
Foreach loopsThis translator can convert many languages into many others:
- Lua to Perl or PHP
- Java to OCaml or GLSL
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.
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.
The Prolog translator is still unfinished and experimental. You can install the package by typing
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:
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
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
Boost (log, When -DWITH_BOOST_LOG=ON; Program_options, When -DLIB_ONLY=OFF)
This universal code generator is one example.