Hacker News new | past | comments | ask | show | jobs | submit login

> Some compilers translate source code into another programming language. These compilers are called source-to-source translators or transpilers

I was wondering how compile-to-JS languages would be classified. Technically they are all transpilers, but seeing as there is no lower-level for the browser than JS (barring WebASM), one could also argue that they are in fact also compilers.

Anyone have any thoughts on this?




> Technically they are all transpilers, but seeing as there is no lower-level for the browser than JS (barring WebASM), one could also argue that they are in fact also compilers.

They're compilers because they translate from one computer language into another. It has nothing to do with how low of a level the browser supports running. They're additionally transpilers (a subset of compilers), because the languages that they translate between are both high-level languages.


So all transpilers are compilers, but not all compilers are transpilers?


Correct. Transpilers are a subset of compilers that go from a HLL to a HLL.


Although the following (from Wikipedia) seems to accord with usage:

> The name compiler is primarily used for programs that translate source code from a high-level programming language to a lower level language (e.g., assembly language, object code, or machine code) to create an executable program.

Maybe we should complicate that a bit by saying that a compiler typically compiles a programming language into a grammar where the higher-level features of the source language must be "expanded" or "linearized" in some substantial way to be expressed in the target language.

So, for example, GHCJS is more like a compiler than a transpiler, even though its target language is JavaScript, because the JavaScript that it generates is full of graph reduction stuff that is implicit in the source Haskell.

On the other hand, CoffeeScript is more like a transpiler, because it doesn't do any such substantial expansion or linearization.


I like that.

Compilers lower input source into something more linear.

Transpilers move input source laterally.

They are different, which I dislike people saying they are not.


Yes.


Transpiler is a recently made up word, and describes something that's just as well described as a compiler. I wouldn't spend too much time hoping for a distinction here.


> Transpiler is a recently made up word

People keep saying this, but it's not true. You can find the word being used, in its modern meaning, as far back as 1964.

https://academic.oup.com/comjnl/article/7/1/28/558689/The-co...


Page 35 of this paper has this sentence.

One can also envisage a "transpiler" capable of converting a program from one such style into another with considerable generality.

Are there any other known citations of the term "transpiler"?


Yes, there is also this book from 1999, which talks about a Pascal to C 'transpiler' around as early as 1989.

https://books.google.co.uk/books?id=vKQSBwAAQBAJ&pg=PR8&lpg=...


The actual author of p2c has the good taste to not call it a transpiler. https://schneider.ncifcrf.gov/p2c/historic/daves.index-2012J...


I'd thought a transpiler is a compiler where the source and target language are the same and the semantics of the program are preserved across transpilation (eg. Closure Compiler, Babel, LLVM optimization passes). That's a useful distinction: it implies that you can feed the output of a transpiler back into the input and at worse the result will be idempotent, and that you can mix transpiled output with raw input and the result will still be interpretable.

Evidently Wikipedia has a more broad definition of source-to-source compilation, which I'd agree is pretty meaningless. The distinction between high- and low-level languages is pretty arbitrary; you can write machine-language "source code", so in some ways all compilers are source-to-source.


We could newspeak it to be an endo-compiler (endo- is greek for internal/within). It runs well with endo-functor.


Compiler/transpiler - same difference.

I think they've gone out of fashion now, but when I learned about compilers we were introduced to T-diagrams, sometimes called tombstone or bratman diagrams and shown how to bootstrap a compiler for a high level language from scratch [1].

Torben Mogensen's Basics of Compiler Design [2] - Chapter 13 is devoted to bootstrapping a compiler, which introduces them.

[1] scratch meaning a computer (with relevant hardware) with a CPU with it's machine code instructions and some way to make files containing those instructions. You can do this even without assembler, that's the first step. Of course no-one would do this now, but it's a necessary step developing the first high level languages and compilers.

[2] http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: