Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Roger L Costello Newsgroups: comp.compilers Subject: Are transpiling techniques different than compiling techniques? Date: Mon, 11 Oct 2021 13:26:01 +0000 Organization: Compilers Central Lines: 56 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <21-10-017@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="94857"; mail-complaints-to="abuse@iecc.com" Keywords: question, translator, comment Posted-Date: 11 Oct 2021 13:55:57 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Accept-Language: en-US Content-Language: en-US X-OriginatorOrg: mitre.org Xref: csiph.com comp.compilers:2725 Hi Folks, Today I learned a new word: transpiling I looked it up and learned that it is converting one source code to another. See below. "Neat!" I thought. "I am converting a military air navigation data format to a civilian air navigation data format, which is a kind of transpiling, I think. I wonder if there are techniques specific to transpiling? Is there a book or tutorial on how to build a transpiler? Are there techniques unique to transpilers? /Roger ----------------------------------------------- Compiler: is an umbrella term to describe a program that takes source code written in one language and produce a (or many) output file in some other language. In practice we mostly use this term to describe a compiler such as gcc which takes in C code as input and produces a binary executable (machine code) as output. Transpilers are also known as source-to-source compilers. So in essence they are a subset of compilers which take in a source code file and convert it to another source code file in some other language or a different version of the same language. The ouput is generally understandable by a human. This output still has to go through a compiler or interpreter to be able to run on the machine. Some examples of transpilers: 1. Emscripten: Transpiles C/C++ to JavaScript 2. Babel: Transpiles ES6+ code to ES5 (ES6 and ES5 are different versions or generations of the JavaScript language) https://stackoverflow.com/questions/44931479/compiling-vs-transpiling [Back in the day, the term was "sift", from a translator from Fortran II to Fortran IV written in 1962. In the late 1960s IBM had a Fortran to PL/I translator which worked (I used it) but generated ugly code due to all the places where the semantics of PL/I were almost but not quite the same as similar looking Fortran constructs: http://bitsavers.org/pdf/ibm/360/fortran/GC33-2002-2_FORTRAN_To_PL1_Translator_Jan73.pdf I think you will find two approaches. There's the half-hearted one in which it translates contstructs into corresponding ones and hopes the differences don't matter, and the full one that is a real compiler with all of the usual analyses and a code generator that happens to generate another high level language. The f2c Fortran to C translator is an example https://www.netlib.org/f2c/f2c.pdf -John]