5

I was wondering between the transpiler and compiler.

For example, I have a language('let's call it foo') and it will be transpiled to javascript.

foo -----transpiled-----> javascript

However, is foo limited under javascript?

Such as: "JavaScript cannot write to files on the server without the help of a server side script"

foo ----x----> write to files on the server without the help of a server side script

If so, is it possible to exit from the limit of javascript?

Such as making foo able to write to file itself.

foo ---------> write to files on the server

Note: What i am asking for is explanation and why and so on, NOT THE CODES!

Note again: Is it possible for it to exit the limits with additional libraries?

Edit: So, if i added another library from another language like python, will it help to exit the limits?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Lok Jun
  • 1,315
  • 2
  • 9
  • 16
  • 7
    If your output is Javascript, it's Javascript. It won't sprout new features or capabilities just because you generated it from something else. – Mat Dec 25 '13 at 10:38
  • Is it possible to create libraries to exit the limits? – Lok Jun Dec 25 '13 at 10:39
  • Libraries that would run where/in what environment? If it's Javascript in a browser, again, those libraries are Javascript in a browser. You won't bypass existing limitations with those. – Mat Dec 25 '13 at 10:41
  • How about like libraries from python? – Lok Jun Dec 25 '13 at 10:42
  • 4
    How would you make a browser run those libraries? And even if you did manage to get a browser to run python code, how would that help in writing files to your web server? That python code would still be running on someone's machine, not on your server. – Mat Dec 25 '13 at 10:48
  • cgi? I wonder if it will be helpful. – Lok Jun Dec 25 '13 at 10:49
  • CGI runs on the server side. – Mat Dec 25 '13 at 10:54
  • so what you want? as said @Mat if you can do this with js, you can do this and with language that compiled to js. With js you can send command to server and run something, so and with foo you can do that, but what you want concrete? – Grundy Dec 25 '13 at 10:54
  • So if I use it as a library, is it possible? – Lok Jun Dec 25 '13 at 10:55
  • I just want a very well-explained answer. – Lok Jun Dec 25 '13 at 10:55
  • 1
    You can't "use CGI as a library". CGI is run on the **server** not the client that runs the JS. – Mat Dec 25 '13 at 10:55
  • Please, answer the question with a well-explained answer. – Lok Jun Dec 25 '13 at 10:57
  • 1
    What you're suggesting is like taking a photo of the television and expecting the photo to move. – Boann Dec 29 '13 at 06:22
  • 2
    And no, you can't "use the television as a library". – Boann Dec 29 '13 at 06:23

2 Answers2

4

Transpiler is a type of compiler that takes the source code of a programming language as its input and outputs the source code into another programming language.

So in output you have file with source on destinationa language, for your sample its javascript, and this file will be executed, so if you create it manualy on javascript it was same result.

so answer on your question: no its not possible exit the limits destinations language, because in the end you can execute program on this language

Grundy
  • 13,356
  • 3
  • 35
  • 55
4

You CAN'T exit the limits of the destination language. You could, however, create a compatibility layer that emulates the missing features and provide the functionality somehow.

In your example, if the foo internal function writefile() is the one that writes files, you could make a library that provides a writefile function that uses ajax to store the files to the server (or a cookie or localstore, etc). The original foo script wouldn't have to be changed for it to work.

And this is precisely one of the main parts about writing a transpiler: You not only have to translate the language, but you also have to emulate the missing features.

(you can also opt to disable the missing features)

chris-l
  • 2,802
  • 1
  • 18
  • 18
  • 3
    Thanks for this: "And this is precisely one of the main parts about writing a transpiler: You not only have to translate the language, but you also have to emulate the missing features." – Lok Jun Dec 30 '13 at 03:08