1. Euphoria to C translator querie

<html><div style='background-color:'><DIV>Hi all,</DIV>
<DIV>Does anyone know who the Eurphoria to C translator actually works. How does
it convert the code. I need to know because I want to make a Basic to C converter
and vise versa.</DIV>
<DIV>Thnaks,</DIV>

new topic     » topic index » view message » categorize

2. Re: Euphoria to C translator querie

This is a multi-part message in MIME format.

------=_NextPart_000_0014_01C11E86.B718EEC0
	charset="iso-8859-1"

I might be hard to beat BCX because the code produced is native
winapi and readable...The Euphoria translator produces what looks
like garbage but it works.

Good luck if you give it a try!

Euman
euman at bellsouth.net

  ----- Original Message -----
  From: craigwoolmer at hotmail.com
  To: EUforum
  Sent: Tuesday, August 07, 2001 12:57
  Subject: Euphoria to C translator querie



  Hi all,
  Does anyone know who the Eurphoria to C translator actually works. How
does it convert the code. I need to know because I want to make a Basic to C
converter and vise versa.
  Thnaks,
  Craig Woolmer


--
  Get your FREE download of MSN Explorer at http://explorer.msn.com




------=_NextPart_000_0014_01C11E86.B718EEC0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

new topic     » goto parent     » topic index » view message » categorize

3. Re: Euphoria to C translator querie

Craig Woolmer writes:
>Hi all,
> Does anyone know who the Eurphoria to C translator actually works.
> How does it convert the code.
> I need to know because I want to make a Basic to C converter and vise
versa.
> Thnaks,
> Craig Woolmer

If you want to make it in Euphoria you have two choices :
1) Your own parser. You must create a parser that will
read the file, split it into tokens.

2) Use David Cuny's Ox. You will create a grammar specifiation
and it will generate a parser in Eu for you.

Then you will read the tokens and translate them to the other
language.

You can look at David Cuny's Euphoria to Java
(http://www.lanset.com/dcuny/java.htm) for inspiration.

The translation to Basic -> C might be easy, but
C -> Basic is more difficult since you have to write
all the wild things C has. (unions, pointers etc.)

Regards,
    Martin Stachon

new topic     » goto parent     » topic index » view message » categorize

4. Re: Euphoria to C translator querie

> 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 message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu