编译器可以识别不同的语言并将它们发送到相应的编译器。可能的?

发布于 2024-08-17 01:33:01 字数 745 浏览 7 评论 0原文

我在想是否可以将asp.net、php和java桥接形成一个页面。

事实上我现在不需要任何这样的东西。这只是我脑海中浮现的一个想法,因为某些语言的某些功能很好,而某些功能或其他一些语言也很好,所以我在想,如果我将所有这些功能组合成一个,

我的意思是,我正在创建一个页面拥有来自所有 3 种语言 asp.net php 和 java 的代码。

<asp code></asp code>
<php code></php code>
<java code></java code>

或者

<html>
    <asp code>
    <php code></php code>
    <java code></java code>
    </asp code>
</html>

类似的东西,编译器可以识别不同的代码段并将它们发送到编译器上运行以执行。 XML 中的输出可以被其他语言识别和使用,

我并不是说所有语言都可以相互交互。虽然他们可以通过XML相互交互。但我只是想说,该文件被编译为具有不同编程语言代码的单个实体,这些代码被发送到各自的编译器以执行并最终返回到父编译器

我正在考虑可以开发的编译器whcih 识别不同的语言代码并将它们发送到编译器,如 .net 框架(例如 MSIL)完成的那样

I was thinking whether it is possible to bridge asp.net, php and java to form a single page.

Actually i dont need any such thing as of now. It was just an idea that stiked to my mind as some features of some languages are good and some features or some other languages are good, so i was thinking what if i combine all these features into one

I mean, I m creating a page that has code from all the 3 languages asp.net php and java.

<asp code></asp code>
<php code></php code>
<java code></java code>

or

<html>
    <asp code>
    <php code></php code>
    <java code></java code>
    </asp code>
</html>

or something like that complier recognize different segments of code and send them to run on their compilers to execute. And output can be recognized and used by other languages in XML

i m not saying that all the languages to interact with each other. Although they can interact with each other through XML. But I only mean to say that the file is compiled as a single entity having different- different programming languages code which are send to their respective compiler to get executed and finally returning back to the parent compiler

I am thinking of a compiler that can be developed whcih recognize different languages code and send them to their compiler as done by .net framework eg MSIL

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

小草泠泠 2024-08-24 01:33:01

是否可以?

引用《辛普森一家》中的洛夫乔伊牧师的话,“用如果来简短回答“不”。用“但是”来详细回答“是”。”

,如果您使用当前可用的技术,目前不可能。

但是它要求您推出自己的服务器,该服务器将充当垫片,分割出不同的代码部分并将它们发送到必需的语言解析器+编译器,然后将这些单独的部分重新组合在一起以显示页面。

编辑:
@Shantanu:我的荣幸。实施完全取决于您,因为我根本没有调查过类似的事情。

最终我觉得这不是最有成效的事情,因为您可能会遇到很多问题。

最大的是:
一种语言的代码不知道其他语言正在做什么。

也就是说,如果您在 ASP 中使用值定义了一个变量,那么 Java 或 PHP 版本无需付出巨大的努力就不会意识到它,更不用说它们将完全无法从彼此的进程访问内存。

但是,如果您确实想走这条路,我建议您研究一下解析器生成器,例如 ANTLR。它将帮助您编写一个可以查找特殊标签的解析器(注意,如果需要,这可以使用正则表达式或手动解析器来完成)。

获得分割代码后,您将需要将其发送到每种语言的编译器,您应该能够从中接收文本输出。有了该文本后,它应该全部是 html + javascript,然后可以将它们重新组合在一起以显示页面。

我想说的是,如果你想让这 3 种语言进行交互,你将创建一个巨大的项目。使用 .Net 框架并为其编写 PHP 和 JAVA(可能已经存在)语言可能会更容易,从而允许您放弃创建整个服务器堆栈。

Is it possible?

To quote reverend Lovejoy from The Simpsons "short answer no with an if. Long answer yes, with a but."

No, it is not currently possible if you use currently available technology.

Yes, but it requires you to roll your own server which would act as a shim, splitting out the different sections of code and sending them to the requisite language parsers + compilers, and then bring those separate sections back together to display the page.

Edit:
@Shantanu: My pleasure. The implementation is completely left up to you as I have not investigated anything like this at all.

Ultimately I feel this is not the most productive thing to do as you will probably run into a large number of issues.

The biggest being:
Code from one language will have no concept of what is being done in the other languages.

i.e. If you have a variable defined with values in your ASP, the Java or PHP versions would be unaware of it without huge effort, not to mention they would be completely unable to access the memory from each other's processes.

However, if you do want to go down this route, I suggest you look into a parser generator like ANTLR. It will help you write a parser which could look for your special tags (note, this could be done with regex or a hand spun parser if needs be).

Once you have the split code, you will want to send it to the compilers for each language, which you should be able to receive textual output from. Once you have that text, it should be all html + javascript, which can then be combined back together to display the page.

I will say that if you want to have the 3 languages interact, you will be creating a HUGE project. It may be easier to use the .Net framework and write the PHP and JAVA (which probably already exist) languages for it, allowing you to forgo creating a whole server stack.

深海蓝天 2024-08-24 01:33:01

不是,不是。脚本是服务器端的,整个文件将依次传递到每个服务器(asp.net/php/java),我相信其他代码会导致解析错误。

这也将是极其低效的。

It's not, no. The scripts being server side, the entire file would be passed to each of the servers (asp.net/php/java) in turn and I believe the other code would cause a parse error.

It'd also be horrendously inefficient.

嘦怹 2024-08-24 01:33:01

虽然与我认为的不完全一样,但生成包含多种客户端语言的页面很简单。只需为脚本标记定义不同的 type 属性,例如:

<html>
    <script type="text/javascript">...</script>
    <script type="text/vbscript">...</script>
    <script type="text/someothersupportedscript">...</script>

    <body>
        ...
    </body>
</html>

另一方面,如果您想在服务器端用不同的语言生成 HTML - 嗯,当然这是可能的 em> 但我不知道有任何框架可以使这变得容易。问题是,几乎每个页面生成服务器端库都希望根据 HTTP 响应的内容形成完整的 HTML 页面。

最简单的方法可能是将一种语言指定为“主要”语言,让该语言实际生成网页,然后让它进行外部调用,最终提供由其他语言生成的页面部分(以及以及将它们全部缝合在一起的逻辑)。这些调用可以是直接进程调用、带有包装器的 RMI、Web 服务调用(对本地或远程主机)等。

不过,我真的不确定您为什么要这样做。 :-)

While not quite what I think you have in mind, it's simple to generate pages that contain multiple client-side languages. Simply define different type attributes for the script tags, e.g.:

<html>
    <script type="text/javascript">...</script>
    <script type="text/vbscript">...</script>
    <script type="text/someothersupportedscript">...</script>

    <body>
        ...
    </body>
</html>

If, on the other hand, you want to generate HTML on the server side from different languages - well, of course it's possible but I'm not aware of any frameworks that will make this easy. The thing is, just about every page-generating server-side library expects to form a complete HTML page based on the contents of an HTTP response.

The easiest way to go about this might be to designate one language as your "primary", have that one actually generate the web page - and then get it to make external calls that ultimately supply the parts of the page generated by other languages (along with the logic to stitch them all together). These calls could be direct process invocation, RMI with wrappers, web service calls (to local or remote hosts), etc.

Still - I'm really not sure why you'd want to do this. :-)

热鲨 2024-08-24 01:33:01

ESI

http://www.akamai.com/html/support/esi.html

本质上,页面是由一系列图块组成的。 Oracle 在其网络缓存产品中实现了这一点,但您自己编写一个解析器就足够简单了。

C.

ESI

http://www.akamai.com/html/support/esi.html

Essentially the page is built up in a series of tiles. Oracle implements this in its webcache products but it'd be simlpe enough to write a parser yourself.

C.

孤云独去闲 2024-08-24 01:33:01

我认为必须设计一个新的编译器来根据一些标签识别不同的源代码,

例如

- 意味着 asp.net
- 表示 php
- C# 代码

像这样
当这个编译器看到这段代码时,

它应该将相应的代码发送给它的编译器。

例如

<aspX>
<asp: Textbox....../>
<C#X>
xyz=abc();
</C#X>
</asp>

类似的东西

I think a new compiler has to be designed to recognize different source code on the basis of some tags

say

<aspX> - means asp.net
<php> - means php
<C#X> - C# code

like this
When this compiler see this code

It should send the corresponding code to its compiler.

eg

<aspX>
<asp: Textbox....../>
<C#X>
xyz=abc();
</C#X>
</asp>

something like that

━╋う一瞬間旳綻放 2024-08-24 01:33:01

我使用 ajax 混合了多种语言。这对于您的情况可能有意义,但您没有提供足够的详细信息。

I've mixed languages using ajax. It may make sense in your case, but you haven't provided enough detail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文