Transpiler和编译器 [英] Transpiler and compiler

查看:156
本文介绍了Transpiler和编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在浏览器和编译器之间感到疑惑。

I was wondering between the transpiler and compiler.

例如,我有一种语言('让我们称之为foo'),它将被转换为javascript。

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

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

然而,foo是否受javascript限制?

However, is foo limited under javascript?

例如:如果没有服务器端脚本的帮助,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

如果是这样,是否可以退出javascript的限制?

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

例如让foo能够写入文件本身。

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?

编辑:所以,如果我从另一种语言如python中添加另一个库,是否有助于退出限制?

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

推荐答案

你可以'T退出目标语言的限制。但是,您可以创建一个兼容层,模拟缺少的功能并以某种方式提供功能。

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.

在您的示例中,如果foo内部function writefile()是写文件的那个,你可以创建一个库,它提供一个writefile函数,使用ajax将文件存储到服务器(或cookie或localstore)等)。原始的foo脚本不需要改变它才能工作。

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)

这篇关于Transpiler和编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆