Questions tagged [code-translation]

For questions regarding the translation of code from one programming language to another. NOTE that asking to have your code translated is not suitable for Stack Overflow.

Translating code from one programming language to another can be as tricky as translating between natural languages. This is due to the fact that languages implement different sets of features and are often designed with very different goals. What comes as a built-in function in one language may have to be developed from scratch (or at least require a library) to achieve the same functionality in another.

An appropriately formed question might be "How do I translate this statement", or "What are the differences between these two statements in different languages". It is not appropriate to ask for your code to be translated.

388 questions
3
votes
1 answer

Translating ML code to C++

I have found a parsing algorithm here, however it is in ML and I'm not too familiar with it. For better understanding of the algorithm I am trying to translate it to an imperative language like C++. Now thee are a few things I'm not sure of or don't…
Peter Lenkefi
  • 1,306
  • 11
  • 29
3
votes
1 answer

Reading .dat file with fixed column width

The code I use in SAS Options symbolgen ps=10000; Data span_nonspan; INFILE 'C:\September 2016\SAMPLE.dat'; INPUT @1 XYZ $10. @11 ABC $7. @18 PM $3. run; Can anyone please help me how to…
3
votes
1 answer

Problems with k-NN example in C++(OpenCV)

I have found the following example in the OpenCV documentation for using k-NN. Now my task is to convert the following code to Java and to do some changes on it because my data is not image. I have some difficulties to understand what is happening…
Jürgen K.
  • 3,427
  • 9
  • 30
  • 66
3
votes
2 answers

Equivalent SIMD instruction for multiplying specific array elements

I just understood how to get a dot-product of 2 arrays (as in the following code): int A[8] = {1,2,3,4,5,1,2,3}; int B[8] = {2,3,4,5,6,2,3,4}; float result = 0; for (int i = 0; i < 8; i ++) { result += A[i] * B[i]; } is equivalent to (in…
Deep Mitra
  • 57
  • 4
3
votes
2 answers

Lua: Decompose a number by powers of 2

This question is a parallel to python - How do I decompose a number into powers of 2?. Indeed, it is the same question, but rather than using Python (or Javascript, or C++, as these also seem to exist), I'm wondering how it can be done using Lua. I…
Josh
  • 3,225
  • 7
  • 30
  • 44
3
votes
2 answers

Elegant way to check empty result of numpy.nonzero

Using the numpy function numpy.nonzero, is there an elegant way to check if the tuples as output are empty arrays? In MATLAB, this is very easy i.e. answer = find( matrix_a < matrix_b ); isempty(answer)
overcomer
  • 2,244
  • 3
  • 26
  • 39
3
votes
2 answers

Is there an equivalent to a nested recursive function in C?

First of all, I know that nested functions are not supported by the C standard. However, it's often very useful, in other languages, to define an auxiliary recursive function that will make use of data provided by the outer function. Here is an…
user1220978
3
votes
3 answers

Getting data from an program written in C# into a Java program

I have a program written in C# that receives data from a third party server and processes it into a series of integers (they are streaming rapidly). The program is written in C# because the third party provides classes to process the data, but only…
Chris W
  • 145
  • 1
  • 2
  • 12
3
votes
1 answer

Automatically translating C source into C89 or C90

So I'm working on this C/C++ library, and I'm using the GNU compiler, which supports the latest standard of C and C++. I want to make my library compatible with the VC++ compiler which only supports C89/C90, not the newer C standards that allow…
turnt
  • 3,235
  • 5
  • 23
  • 39
3
votes
1 answer

String Template: make all variable declaration global

I am trying to implement a translator using ANTLR+StringTemplate. I have a starting language that is java like and multiple destination language. I used the example:…
3
votes
2 answers

Does j2objc really support reflection?

I'm trying to use j2objc to translate some Java code. Unfortunately, my code relies on reflection. The j2objc documentation claims that reflection is supported, but when I try to import e.g java.lang.reflect.Field, I get an error message saying it…
user1432855
2
votes
4 answers

How to add an event handler in VB.NET?

This code is part of AjaxControlToolkitSampleSite. To be exact, it is in the AsyncFileUpload control: AsyncFileUpload1.UploadedComplete += new EventHandler(AsyncFileUpload1_UploadedComplete); How can I translate this to…
2
votes
3 answers

Translation of Scheme code for Sierpinski carpet

I found code for generating Sierpinski carpet at http://rosettacode.org/wiki/Sierpinski_carpet#Scheme - but it won't run in the DrRacket environment or WeScheme. Could someone provide solutions for either environments?
lifebalance
  • 1,846
  • 3
  • 25
  • 57
2
votes
1 answer

ANTLR How to get rewrited code source? (using TokenRewriteStream)

I am trying to create simple translator translating something like: aaa | bbb | ccc to 1 : aaa 2 : bbb c : ccc Here is grammar test01.g: grammar test01; options { output=AST; } @members{ int N; } test @init{ N = 0; }: id ('|' id)*…
Astronavigator
  • 2,021
  • 2
  • 24
  • 45
2
votes
1 answer

AST to XML in generally (maybe ANTLR)

I need to parse files written in some languages(Java, C, C#...) and then trace the AST(Abstract syntax tree) to xml. (Actually the aim is to manipulate it and trace to another language - this second part have been implemented). After investigation I…
Michael
  • 23
  • 1
  • 6