1

There're multiple topics about bootstrapping a compiled language, languages that are compiled into machine code directly; However, I can't find good explanation about bootstrapping a transpiled language. First, The difference between a transpiler and a compiler is that the former converts a language into another, unlike a compiler that emits machine code. The question now, If Language X is transpiled into JavaScript, and Language X traspiler/compiler is written in Language X but it always ends up being JavaScript before it runs... is that still bootstrapping?

To clarify, the confusion lies in the difference between compiling to machine code vs compiling to another language e.g. JS

  • 4
    A transpiler is a program which takes a program in language A and transform it into a semantically equivalent program in language B. A compiler is a program which takes a program in language A and transform it into a semantically equivalent program in language B. They are two different words for the exact same thing. Why do you think that calling it one name would make it behave differently than calling it another name? – Jörg W Mittag Jul 06 '19 at 07:31
  • The primary difference being that a compiler typically produces object code or binary code, while a transpiler typically produces source code in another language. Otherwise, yeah, they do exactly the same thing. – Robert Harvey Jul 06 '19 at 23:05
  • Other than readability, what is the difference between "binary code" and "source code"? Bearing in mind the existence of emulators, which interpret binary code, and things like Lisp machines, which execute human readable lisp code in hardware? – Sean Reid Jul 11 '19 at 13:56
  • Nowadays, new languages are bootstrapped by writing a parser for them and its output fed to an existing compiler. This saves a lot of work and immediately gives the new language access to all the libraries. This means things like file I/O do not need to be written for it. It just uses the existing libraries. – shawnhcorey Jul 18 '19 at 17:10

2 Answers2

2

For example, Language X is transpiled into Javascript, and Language X traspiler/compiler is written in Language X but it always ends up being javascript before it runs... so is that still bootstrapping?

Sure is.

It's so confusing specially thinking about what happens if Language X's syntax changes after it's bootstrapped, would the traspiler need to be re-written?

You would need to change the X-to-JS transpiler to support the new language syntax. Once you do this the first time, you'll have an X2-to-JS transpilar. You can then refine your transpiler code base (taking advantage of the new language features), and build the transpiler using X2-to-JS transpiler.

For example, perhaps your first version of X only supports while loops. All throughout your transpiler codebase, you have to hold yourself back from using for loops, because they're not available. Once you get you basic language X working, you can add for loops into the next version, X2. Now that you have a X2-to-JS transpiler, you can go back and refine your code base, replacing while loops with the newly available for loops wherever appropriate.

Robert Harvey
  • 199,517
Alexander
  • 4,884
2

Your question is somewhat unclear because there is no clear definition of what is and isn't a transpiler.

However, I suspect the distinction you are thinking of is that a compiler produces a program that runs natively on your computer whereas a transpiler produces a program that does not run natively but instead depends on another language.

For example, Language X is transpiled into Javascript, and Language X traspiler/compiler is written in Language X but it always ends up being javascript before it runs... so is that still bootstrapping?

I do see what you mean, Language X isn't totally independent of the other language, it still requires JavaScript to run. If the Language X compiler produced native machine code it would be fully independent.

But the term bootstrapping in programming languages refers specifically to the language compiling itself without concern for the target language. So, yes, as the term is generally used, such a language is bootstrapped.

It's so confusing specially thinking about what happens if Language X's syntax changes after it's bootstrapped, would the traspiler need to be re-written?

Firstly, the compiler vs transpiler distinction does not matter here. In either case, introducing syntax changes into a self-compiling language is a bit tricky.

Yes, the compiler has to be changed to support the new syntax. Of course, it would be very painful if the compiler constantly had to be rewritten with every change. Generally, languages are not self-supporting while they are initially being developed. Only once the syntax is relatively stable is a self-compiling compiler implemented. Once a language is more stabilized, most features are backwards compatible, allowing old code to continue working. Thus, it is isn't necessary to rewrite the compiler constantly, it can just use the same syntax.

Robert Harvey
  • 199,517
Winston Ewert
  • 24,862