Re: Euphoria to C translator querie

new topic     » goto parent     » topic index » view thread      » older message » newer message

> Craig Woolmer wrote:

>> Does anyone know who the Eurphoria to C translator
>> actually works.

Well, the easiest thing to do is throw code at it, and see what it actually
generates. For example, here's a program:

   integer i
   i = 100

EC generates a lot of code, but the main bits are in INIT_.C:

   int 0i;

and MAIN_.C:

   0i = 100;

from this, we can deduce that a pattern of the form:

   integer <name>

will generate the code:

   int _0<name>;

and an assignment of a constant to an integer will generate the code:

   _0<name> = <constant>;

Now for something a bit more complex:

   integer i, j, k
   i = 10
   j = 20
   k = i + k

This generates:

   int _0i;
   int _0j;
   int _0k;

and:

   _0i = 10;
   _0j = 20;
   _0k = _0i + 0j;

Fairly simple stuff, until you start working with more complicated
datatypes, like atoms, sequences and objects. For example, adding atoms
looks something like this:

_0 = _0a;
if (IS_ATOM_INT(_0a) && IS_ATOM_INT(_0b)) {
    _0a = _0a + _0b;
    if (_0a + HIGH_BITS >= 0)
        _0a = NewDouble((double)_0a);
}
else {
    if (IS_ATOM_INT(_0a)) {
        _0a = NewDouble((double)_0a + DBL_PTR(_0b)->dbl);
    }
    else {
        if (IS_ATOM_INT(_0b)) {
            _0a = NewDouble(DBL_PTR(_0a)->dbl + (double)_0b);
        }
        else
            _0a = NewDouble(DBL_PTR(_0a)->dbl + DBL_PTR(_0b)->dbl);
    }
}
DeRef(_0);

That's a fair amount of code, and the more you look at EC's output, the more
complex it gets.

>From a technical standpoint, it's certainly *possible* to reverse-engineer
EC, but  the license prohibits doing that. Even if you could, you don't have
the source code for a lot of critical functions, like binary_op().

>> I need to know because I want to make a Basic to C
>> converter and vise versa.

If you want to write a Basic to C converter, it might be more profitable to
look at Kevin Diggin's BCX program which does just that. He doesn't supply
the source code, but examining the output of the program can be educational.

Having the right tools for the job also helps. I've written a tool called
'Ox' that is sort of the Euphoria equivalent to Yacc and Lex, combined into
a single program.

You might also find my own Basic interpreter of interest:

   http://www.lanset.com/dcuny/wxbasic.htm

Although it's written in C, not Euphoria.

-- David Cuny

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu