C to Modula2 converter? 
Author Message
 C to Modula2 converter?

PG>   Recently someone asked about a Modula2 to C converter. I would
PG>   be interested in a program that converts C to Modula2. Does such
PG>   a program exist? I believe it is very difficult to translate C code
PG>   to Modula2 because of the (cryptic) notational possibilities of C.
PG>   Any info would be appreciated.

One of the main difficulties is that C is like 2 languages in one. The
macro preprocessor is one language, and it affects the program text seen by
the C compiler.  Unfortunately many C programs depend heavily on using the
macro preprocessor to produce different code under different circumstances
so there is often no direct equivalence between C code and Modula-2 code.

We thought about writing one once but decided that it would probably
create more unhappy people than it would please.

Best Regards
     Sean Wilson
     (TopSpeed Technical Support)

___
 X PQ-Under-Trial 2.15 X Surge into electronic mail.

--  
uucp: uunet!m2xenix!puddle!139!590!Sean.Wilson



Mon, 26 Jun 1995 19:36:18 GMT  
 C to Modula2 converter?

  A C to Modula-2 converter is not possible, since Modula-2 does
not support set complement, structured constants, or null
procedure variables.  Oberon corrects the first two design flaws.

--  
uucp: uunet!m2xenix!puddle!6.0!Robert.Barton



Thu, 29 Jun 1995 11:03:28 GMT  
 C to Modula2 converter?

|>   A C to Modula-2 converter is not possible, since Modula-2 does
|> not support set complement, structured constants, or null
|> procedure variables.

Not possible is a bit strongly worded, considering that I can think
of solutions to all three problems.

However, much as I like Modula-2, I can't quite see why one would
want a C to Modula-2 converter.  (Flames to /dev/null, please.)

--
Robert Marti                    |  Phone:    +41 1 254 72 60
Informationssysteme             |  FAX:      +41 1 262 39 73

CH-8092 Zurich, Switzerland     |



Fri, 30 Jun 1995 16:10:26 GMT  
 C to Modula2 converter?

Quote:


>|>   A C to Modula-2 converter is not possible, since Modula-2 does
>|> not support set complement, structured constants, or null
>|> procedure variables.

>Not possible is a bit strongly worded, considering that I can think
>of solutions to all three problems.

  The lack of structured constants can be worked around to an extent
by using variables and a long sequence of assignments.  There are
no substitutes for the other two problems, though.


Sat, 01 Jul 1995 17:12:53 GMT  
 C to Modula2 converter?

(Joe Bob) writes in an ongoing thread with contributions form
Robert Barton (RB) and myself (RM):

RB >>> A C to Modula-2 converter is not possible, since Modula-2 does
RB >>> not support set complement, structured constants, or null
RB >>> procedure variables.

RM >>  Not possible is a bit strongly worded, considering that I can think
RM >>  of solutions to all three problems.

JB >   The lack of structured constants can be worked around to an extent
JB >   by using variables and a long sequence of assignments.  There are
JB >   no substitutes for the other two problems, though.

Let's see.

Set complement:

The set complement of an expression expr of type
    FooSet = SET OF [lb .. ub]
is
    {lb .. ub} - expr
(see sections 5 and 8.2.3 of the report).

Null procedure variables:

A "clean" solution would be to generate a
    PROCEDURE NullProcT(p1: T1, ... , pn: Tn): RetT;
      BEGIN
        (* you may need to return something of type RetT here *)
      END NullProcT
for each
    TYPE ProcT = PROCEDURE (T1, ... , Tn): RetT
and replace tests
    p = NIL  (or p # NIL, respectively their C counterparts)
for a variable p of type ProcT with tests
    p = NullProcT  (or p # NullProcT).

Another possibility is to generate an additional type
    ProcTWithNull = RECORD CASE BOOLEAN OF
                      TRUE:  proc: ProcT
                    | FALSE: adr:  SYSTEM.ADDRESS
                    END
for each type ProcT, declare all respective procedure variables p
to be of type ProcTWithNull (not of type ProcT!), write all calls as
    p.proc(...)
and write all tests for NULL (or NIL) as
    p.adr = NIL  (or p.adr # NIL)

Disclaimer: I haven't tried the latter solution, but I think
it should work.  In any case, it's a hack.

--
Robert Marti                    |  Phone:    +41 1 254 72 60
Informationssysteme             |  FAX:      +41 1 262 39 73

CH-8092 Zurich, Switzerland     |



Sat, 01 Jul 1995 22:43:58 GMT  
 C to Modula2 converter?

Quote:
> One of the main difficulties is that C is like 2 languages in one. The
> macro preprocessor is one language, and it affects the program text seen by
> the C compiler.  Unfortunately many C programs depend heavily on using the
> macro preprocessor to produce different code under different circumstances
> so there is often no direct equivalence between C code and Modula-2 code.

> We thought about writing one once but decided that it would probably
> create more unhappy people than it would please.

I'm glad to see TopSpeed on the net. Is this the promised Compuserve
connection?

TopSpeed of all people should be able to easily produce a translator since you
use a common code generator between C and M2 ...

Is it worth it? What about companies who state that they would like to use a
safer language but they have a large commitment in existing C source. You
partially address this already.
(shame that you only ship TS calling convention C libraries. This precludes
simple linking with 3rd party C and causes all sorts of headaches)

  TC.



Sat, 01 Jul 1995 11:01:22 GMT  
 C to Modula2 converter?

Quote:




> >|>   A C to Modula-2 converter is not possible, since Modula-2 does
> >|> not support set complement, structured constants, or null
> >|> procedure variables.

> >Not possible is a bit strongly worded, considering that I can think
> >of solutions to all three problems.

>   The lack of structured constants can be worked around to an extent
> by using variables and a long sequence of assignments.  There are
> no substitutes for the other two problems, though.

This is not the case.

(1) Set complement. Consider you have a set

       TYPE MySet = SET OF [a..b];

    then you get the complement by using the "-" operator:

       PROCEDURE Complement(set: MySet) : MySet;
       BEGIN
          RETURN MySet{a..b} - set
       END Complement;

(2) Null procedure variables. Define for each procedure type a
    dummy procedure:

       TYPE MyProcedureType = PROCEDURE (....);

       PROCEDURE NilMyProcedureType(....); END NilMyProcedureType;

    Now you can assign nil values and compare against them.

--
_______________________________________________________________________________

Andreas Borchert, University of Ulm, SAI, D-W-7900 Ulm, Germany



Sun, 02 Jul 1995 16:05:57 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Modula2 as First CS Language

2. MODULA2 AS FIRST CS LANGU

3. Modula2 as first CS Language

4. Modula2 as first CS language

5. modula2 to C converter

6. searching modula2 to pascal converter

7. Modula2 -> C converter wanted

8. C to Modula2 converter?

9. C to Modula2 converter?

10. Modula2 to C converter?

11. Looking for MODULA2 converter

12. to CS: or not to CS: in F-PC assembler

 

 
Powered by phpBB® Forum Software