<p>Nikhil Kothari's <a href="http://projects.nikhilk.net/ScriptSharp/" rel="nofollow noreferrer">Script#</a> is quite possibly one of the most amazing concepts I've seen in the JavaScript arena for quite some time. This question isn't about JavaScript, but rather about language compilation in the .NET runtime.</p>

<p>I've been rather interested in how, using the .NET platform, one can write a compiler for a language that already has a compiler (like C#) that will generate separate output from the original compiler while allowing the original compiler to generate output for the same source during the same build operation, all the while referencing/using the output of the other compiler as well.</p>

<p>I'm not entirely sure I even understand the process well enough to ask the question with the right details, but this is the way I currently see the process, as per diagrams in the Script# docs. I've thought about many things involving complex language design and compilation that may be able to take advantage of concepts like this and I'm interested in what other people think about the concepts.</p>

<p>--</p>

<p>Edit: Thanks for commenting,so far; your information is, in it's own right, very intriguing and I should like to research it more, but my question is actually about how I would be able to write my own compiler/s that can be run on the same source at the same time producing multiple different types of (potentially) interdependent output using the CLR. Script# serves as an example since it generates JavaScript and an Assembly using the same C# source, all the while making the compiled Assembly cooperate with the JavaScript. I'm curious what the various approaches and theoretical concepts are in designing something of this nature.</p>

[{'answer_id': 75397, 'author': 'ibz', 'author_id': 5475, 'author_profile': 'https://Stackoverflow.com/users/5475', 'pm_score': 0, 'selected': False, 'text': "<p>So let's say you want to compile C# into Javascript. You are asking whether you can take advantage of the existing C# compilers, so instead of compiling C# into Javascript directly you actually convert the MSIL generated by the C# compiler into Javascript?</p>\n\n<p>Sure, you can do that. Once you have the MSIL binary you can do whatever you want to it.</p>\n"}, {'answer_id': 75583, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 0, 'selected': False, 'text': '<p>Microsoft has a research project called <a href="http://labs.live.com/volta/" rel="nofollow noreferrer">Volta</a> which, amongst other things, compiles msil to JavaScript.</p>\n\n<blockquote>\n  <p>a developer toolset for building\n  multi-tier web applications using\n  existing and familiar tools,\n  techniques and patterns. Volta’s\n  declarative tier-splitting enables\n  developers to postpone architectural\n  decisions about distribution until the\n  last possible responsible moment.\n  Also, thanks to a shared programming\n  model across multiple-tiers, Volta\n  enables new end-to-end profiling and\n  testing for higher levels of\n  application performance, robustness,\n  and reliability. Using the declarative\n  tier-splitting, developers can refine\n  architectural decisions based on this\n  profiling data. This saves time and\n  costs associated with manual\n  refactoring. In effect, Volta extends\n  the .NET platform to further enable\n  the development of software+services\n  applications, using existing and\n  familiar tools and techniques.</p>\n  \n  <p>You architect and build your\n  application as a .NET client\n  application, assigning the portions of\n  the application that run on the server\n  tier and client tier late in the\n  development process. You can target\n  either web browsers or the CLR as\n  clients and Volta handles the\n  complexities of tier-splitting. The\n  compiler creates cross-browser\n  JavaScript for the client tier, web\n  services for the server tier, and all\n  communication, serialization,\n  synchronization, security, and other\n  boilerplate code to tie the tiers\n  together. In effect, Volta offers a\n  best-effort experience in multiple\n  environments without requiring\n  tailoring of the application.</p>\n</blockquote>\n'}, {'answer_id': 155447, 'author': 'sirwart', 'author_id': 6222, 'author_profile': 'https://Stackoverflow.com/users/6222', 'pm_score': 3, 'selected': True, 'text': "<p>It's important to realize that all a compiler does is take a source language (C# in this case), parse it so the compiler has a representation that makes sense to it and not humans (this is the abstract syntax tree), and then does a naive code generation to the target language (msil is the target for languages that run on the .NET runtime).</p>\n\n<p>Now if the script# code is turned into an assembly and interacts with other .NET code, that means this compiler must be generating msil. script# is using csc.exe for this, which is just the standard c# comiler. Now to generate the javascript, it must take either c# or msil, parse it, and generate javascript to send to the browser. The docs says it has a custom c# -> js compiler called ssc.exe. </p>\n\n<p>To make things interact consistently on both the client side and the server side it has a set of reference assemblies that are written in .NET but are also compiled to javascript. This is not a compiler specific issue though, those reference assemblies are the script# runtime. The runtime is probably responsible for a lot of the script# magic you're perceiving though.</p>\n"}]
['https://Stackoverflow.com/questions/75258', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8543/']