Are there any programs for converting code from some popular scripting language in C ++ . Converters that add dependencies to the code are not interested. It will be enough for me if the converter can convert only a part of the original language.

An example of what I want to get:

a = [1, 3, 2] a.sort() print(a) 

vvv

 #include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { vector<int> a = {1, 3, 2}; sort(a.begin(), a.end()); for (int i = 0; i < a.size(); i++) { cout << a[i] << " "; } } 

Where can be useful:

  1. Sometimes you need to write a small script for which speed is critical. The existence of such a converter will save time.
  2. In a scripting language, it may be easier to write an algorithm, and it will most likely be clearer. Such a converter is useful not to write the same code several times.

Closed due to the fact that the issue is too common for participants Vlad from Moscow , jfs , Abyx , aleksandr barakin , Harry May 7 '17 at 17:46 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What is Cython not suitable for? - avp
  • @avp C ++ code is useful for easy integration with an existing project. If there is a need for even more performance, I think it will be easier to change the already generated code in C ++. - pank
  • @pank: Cython and C ++ support, example . Naively written Python can be faster naively written C ++, an example . There are many tools that take a certain subset of Python and declare some kind of optimization (eg, theano, numexpr). Pypy translate.py can RPython (a subset of Python) to transform, for example - jfs
  • one
    @AlexanderZonov, gene code based on man swapcontext (or look in the web implementation of coroutines on siglongjmp) - avp

1 answer 1

Found transpilers in C ++ :

  1. Typescript to C: ts2c
  2. Wikipedia article with a list of several transpilers .
  • I found the translator in C ++ (from the link to the wiki) only with python - avp
  • @avp if the translator in C is adequate, then it can be considered as a translator in C ++, there are many of them, but there are few of the scripting languages. - pank