0

I am looking into the logic behind applications like Unity3d, that allow you to write code with JS, C# or Boo, and then compile in a common language (I believe it is plain C++), making the editor independent from a specific language. Allowing users to write code in either language (or all of them at once, in different scripts, inside the same project).

Is there something already "packaged" and ready to use, or something where I can actually learn how to accomplish something similar to what Unity does? The idea is to use only few languages; JS and Python seems to be the ones that pop most often among search for conversion, so probably I would start with these.

I was told that this can be accomplished mainly with parsing of the source code, using regular expressions. Didn't find much beside this approach.

I am aware of the problems related to the different syntax and API, among different languages; which is why instead of re-inventing the wheel, I did decide to search for existing methodologies and try to apply them. Any pointer would be really appreciated.

  • I'd start by reading up on the Common Language Runtime and Java Virtual Machine. – Doval Feb 9 '17 at 4:25
  • CLR is a good example, since .NET use VB, C# and C++. Is there a way to implement a basic version of the CLR with examples? I get the overall view about how the system works, but I am looking also to an example for the implementation. Thanks for your reply – rataplan Feb 9 '17 at 5:32
1

Python, and I believe many other languages, first parses the source code into an abstract syntax tree, AST, as do the GCC, (GNU Compiler Collection), tools which is then further processed including, depending on settings, flags, target, etc., optimisations, etc.

The AST can then be used to generate either machine specific code or, in pythons case at least, codes for the virtual machine.

In the case of GCC this allows you to code a program, (with a little care), in multiple languages possibly with the risk of a degree of overhead and bloat due to interfacing and possible library function duplication, (as there are a number of language specific libraries each of which may provide some of the same functionality).

The python AST library allows processing of python into abstract syntax trees, (more information) and gcc has options that allow the output of such trees.

This is quite a major area of study and I am reasonably sure that most modern tools that allow automatic translation between programming languages use this more extensively than regular expressions.

  • Thanks a lot for the explanation; it is indeed more complex than what I thought. I understand now all the work that went into Unity to make something as complex as this. At least I have a starting point to explore upon, thanks again – rataplan Feb 10 '17 at 3:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.