views:

262

answers:

6

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

A: 

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

Neil N
i was also thinking about ajax. that could it be possible through ajax. But can it be done on a single page ? bit confused. Plz post an eg if possible
Shantanu Gupta
If you mean that you've utilised webservices written in several languages using AJAX, that's not the same as a webservice is effectively language-neutral.
adam
I dont know about webservice at all. I m new to web development and only know little bit about AJAX, javascript and all these things
Shantanu Gupta
+1  A: 

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.

adam
@adam : plz see my answer. I m thinking in that way, plz comment how correct or wrong I am. I m curious to know about it
Shantanu Gupta
A: 

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. :-)

Andrzej Doyle
I m taking about server side languages not client side languages. As client side languages are surely possible. That i know
Shantanu Gupta
+5  A: 

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.

Darien Ford
@Darien Ford: thx for answer. I m very much satisfied with your answer. I would like to know whether a compiler can communicate with other existing compiler for sendind and receiving their code execution related request. How can I make some compiler to make understand you have to execute this piece of code and return me an output. ? for eg what i mean to say. check my answer
Shantanu Gupta
@Darien Ford : different languages can communicate only through XML only or some other common platform. If different languages interact with each other then ofcourse it will become a 100 year project for me as i m a started in programming just spent 1 year in programming on my own not in any indrustry yet. But i was thinking it as if these can be used as an scripts. Just paste a php or java or .net script that will provide me certain output.
Shantanu Gupta
@Shantanu: If you are comfortable leaving them separate, and just use their resulting html output, it will make your life easier. E.g. Assuming you do your "shim" in .Net, you can take the different sections of code, create a web request for each one and send them to the different servers (IIS, Apache, etc) running on your machine, giving you the resultant HTML, and then combine them to output to the user.
Darien Ford
A: 

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.

symcbean
A: 

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

Shantanu Gupta
I didn't downvote, but my guess is that they feel this is more of a wish and less of an answer.
Chuck