Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transpiler and compiler

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?

like image 453
Neo Lok Jun Avatar asked Dec 25 '13 10:12

Neo Lok Jun


2 Answers

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)

like image 123
chris-l Avatar answered Oct 02 '22 19:10

chris-l


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

like image 40
Grundy Avatar answered Oct 02 '22 21:10

Grundy