On 01/26/2011 12:56 PM, Mark Knecht wrote:
> Michael,
>    Thanks for the inputs. It gives me more to think about.
> 
>    In this case the input language is interpreted, not compiled. The
> trading platform interprets the program and internally turns it into
> buy & sell operations. (Not the piece of code I supplied - that was
> just a small function.) Unfortunately, as the language is proprietary
> to the trading platform there isn't a way to go to any common
> low-level language.
> 
>    The 'battery of tests' would be, I think, the trading program being
> executed on a certain market, producing a certainly list of buy & sell
> operations and a specific gain or loss. It would be quite easy to
> compare the outcome because it's nothing more than a list of trades.
> If the translated code generates the same list then it works. If not,
> I dig into why. This part of the task seems relatively straight
> forward to me.
> 
>    I was mainly hoping to find a tool that might generate _reasonable_
> C code, even if it's not perfect. If the C code compiles and runs then
> I could determine what works, what doesn't, and start fixing things.
> I'm not a C programmer and haven't touched that language in at least
> 15 years so anything that moves me forward would be helpful.
> 
>    Again, I do appreciate your inputs. If this extra info gives you
> any new ideas please let me know.

If you don't even have a common low-level language, what you're
essentially doing is creating a compiler for EasyLanguage. Take a small
example, adding two integers in E.L. I won't pretend to know the syntax,
but let's just assume that you have two integers (or numbers or
whatever) 'a' and 'b' declared.

How do you translate "a+b" to C code? You can declare two ints 'a' and
'b' in C, of course. But these are 32- or 64-bit integers. So if 'a' and
'b' are large, "a+b" will overflow. Do EasyLanguage integers work that
way? Probably not...

How about "a/b"? Does EasyLanguage do integer division, or does it treat
them like floats? If it does treat them like floats, do the rounding and
precision agree with C floats? Probably not, so floats are out too.

If you try to fix all of these problems, what you'll end up with is
something like a struct EasyLanguageInteger {...} with associated
functions add_easylanguage_integers, divide_easylanguage_integers, etc.
Then, you can translate "a+b" into add_easylanguage_integers(a, b) where
'a' and 'b' are now structs instead of just ints or floats.

Then, you'll have to write a parser that understands the rules of
precedence, looping constructs, functions, and everything else so that
they can be converted into the appropriate structs and function calls.
At the end, if it works, you'll have an EasyLanguage compiler.

Without a spec (the language is proprietary?), you'd have to guess at
most of that stuff anyway, so the chances you'd get it all right are
about zero.

Your best bet[1] is to create a ton of test data, and feed it to the
E.L. program. Make sure the test data triggers any edge cases. Then you
can attempt to rewrite the code in C, and compare the output. You as a
human who understands what the code does can take a lot of shortcuts
that a translator couldn't.


[1] I'm assuming you want to do this for a relatively small number of
programs, and that writing a compiler would not actually be less
time-consuming.

Reply via email to