From: lo jenny
Subject: any software can translate C to lisp?
Date: 
Message-ID: <b3aob0$1ptm$1@justice.itsc.cuhk.edu.hk>
is there any free download software can translate C to lisp?
Thanks

From: John Thingstad
Subject: Re: any software can translate C to lisp?
Date: 
Message-ID: <oprk4i5qscxfnb1n@news.chello.no>
Sure.. The human mind.
Seriously mechanically translating two such different languages is never a 
good idea.
Instead of a litteral translation examine the program behaviour and start 
from there.
This may not be as much work as it sounds.
Afterall most of the program developement time goes into finding design 
solutions not coding them.

On Sun, 23 Feb 2003 23:10:09 +0800, lo jenny <·······@cuhk.edu.hk> wrote:

> is there any free download software can translate C to lisp?
> Thanks
>
>
>

-- 
John Thingstad
From: Paul Dietz
Subject: Re: any software can translate C to lisp?
Date: 
Message-ID: <3E5B8F47.1BDE33E0@motorola.com>
John Thingstad wrote:
> 
> Sure.. The human mind.
> Seriously mechanically translating two such different languages is never a
> good idea.
> Instead of a litteral translation examine the program behaviour and start
> from there.
> This may not be as much work as it sounds.
> Afterall most of the program developement time goes into finding design
> solutions not coding them.


KCL-derived lisps (gcl, ecl) compile lisp programs by translating
them to C.

You probably don't want to read that C, though.

	Paul
From: Pascal Bourguignon
Subject: Re: any software can translate C to lisp?
Date: 
Message-ID: <87bs10fczw.fsf@thalassa.informatimago.com>
John Thingstad <··············@chello.no> writes:
> > is there any free download software can translate C to lisp?
> > Thanks
>
> Sure.. The human mind.
> Seriously mechanically translating two such different languages is
> never a good idea.
> Instead of a litteral translation examine the program behaviour and
> start from there.
> This may not be as much work as it sounds.
> Afterall most of the program developement time goes into finding
> design solutions not coding them.

There is a FORTRAN-IV to Lisp translator: f2cl.

For examples, it takes this file:
------------------------------------------------------------------------
C RESOLUTION D'EQUATIONS DU SECOND DEGRE.

    5 READ (5,1,END=2) A,B,C
    1 FORMAT (3F10.0)
      IF (A .NE. 0) GO TO 100
      IF (B .NE. 0) GO TO 100
      IF (C .NE. 0) GO TO 100
      GO TO 2
  100 DELTA = B**2-4*A*C
      IF (DELTA .LT. 0) GO TO 10
      X1=(-B-SQRT(DELTA))/(2*A)
      X2=(-B+SQRT(DELTA))/(2*A)
      PRINT 4,A,B,C,X1,X2
    4 FORMAT ('A=',F10.0,' B=',F10.0,' C=',F10.0,' X1=',E15.6,
     -        ' X2=',E15.6)
      GO TO 5
   10 PRINT 14,A,B,C
   14 FORMAT ('A=',F10.0,' B=',F10.0,' C=',F10.0,
     -        ' PAS DE SOLUTION REELLE')
      GO TO 5
    2 STOP 1
      END
------------------------------------------------------------------------

and produce this file:

------------------------------------------------------------------------
;;; Compiled by f2cl version 2.0 beta 2002-05-06
;;; Options: ((:prune-labels nil) (:auto-save t) (:relaxed-array-decls t)
;;;  (:coerce-assigns :as-needed) (:array-type ':simple-array)
;;;  (:array-slicing t) (:declare-common nil) (:float-format single-float))

(defun *main* nil
 (prog ((x2 #1=0.0f0) (x1 #1#) (delta #1#) (c #1#) (b #1#) (a #1#))
  (declare (type single-float a b c delta x1 x2)) label5
  (f2cl-lib:fortran_comment
   "***WARNING:  READ statement may not be translated correctly!")
  (setf a (read)) (setf b (read)) (setf c (read))
  (f2cl-lib:fortran_comment
   "***WARNING: Preceding READ statements may not be correct!")
  (if (/= a 0.) (go label100)) (if (/= b 0.) (go label100))
  (if (/= c 0.) (go label100)) (go label2) label100
  (setf delta (+ (expt b 2.) (* -4. a c))) (if (< delta 0.) (go label10))
  (setf x1 (/ (- (- (f2cl-lib:fsqrt delta)) b) (* 2. a)))
  (setf x2 (/ (- (f2cl-lib:fsqrt delta) b) (* 2. a)))
  (f2cl-lib:fformat t
   ("A=" 1. (("~10,0,0,'*,F")) " B=" 1. (("~10,0,0,'*,F")) " C=" 1.
    (("~10,0,0,'*,F")) " X1=" 1. (("~15,6,2,0,'*,,'EE")) " X2=" 1.
    (("~15,6,2,0,'*,,'EE")) #2="~%")
   a b c x1 x2)
  (go label5) label10
  (f2cl-lib:fformat t
   ("A=" 1. (("~10,0,0,'*,F")) " B=" 1. (("~10,0,0,'*,F")) " C=" 1.
    (("~10,0,0,'*,F")) " PAS DE SOLUTION REELLE" #2#)
   a b c)
  (go label5) label2 end_label (return nil)))
------------------------------------------------------------------------

Not much better, is it.


It would be hard to produce lisp  code from C that would not be silly,
if  only because  the differences  in  the handling  of variables  and
types.  Just try to translate by hand this function for example:


    int fun(char* inch,char* outch,int* inarray,int* outres)
    {
        int i=0; for(i=0;inarray[i]!=0;i++);*outres=i;
        printf("%s\n",inch);
        outch[0]=(char)(inarray[0]);
        outch[1]=(char)(inarray[1]);
        return(outch[0]==outch[1]);
    }


-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
There is a fault in reality. Do not adjust your minds. -- Salman Rushdie
From: JP Massar
Subject: Re: any software can translate C to lisp?
Date: 
Message-ID: <3e5bb52a.55002367@netnews.attbi.com>
On Sun, 23 Feb 2003 23:10:09 +0800, "lo jenny" <·······@cuhk.edu.hk>
wrote:

>is there any free download software can translate C to lisp?
>Thanks
>
>

I believe there used to be a C compiler for Symbolics' machines
(for all I know the code may still exist),  and that it translated
C code into Lisp.
From: Michael Parker
Subject: Re: any software can translate C to lisp?
Date: 
Message-ID: <250220031759373210%michaelparker@earthlink.net>
In article <·················@netnews.attbi.com>, JP Massar
<······@alum.mit.edu> wrote:


> I believe there used to be a C compiler for Symbolics' machines
> (for all I know the code may still exist),  and that it translated
> C code into Lisp.

There was a very early one that translated to Lisp, but it wasn't ANSI
CL by any stretch of the imagination.  However, it was superceded, and
the one on my Symbolics doesn't go to lisp at all, instead compiling to
machine code just like any other C compiler.
From: Christopher C. Stacy
Subject: Re: any software can translate C to lisp?
Date: 
Message-ID: <u65r7n8tb.fsf@dtpq.com>
>>>>> On Tue, 25 Feb 2003 18:28:33 GMT, JP Massar ("JP") writes:

 JP> On Sun, 23 Feb 2003 23:10:09 +0800, "lo jenny" <·······@cuhk.edu.hk> wrote:
 >> is there any free download software can translate C to lisp?

 JP> I believe there used to be a C compiler for Symbolics' machines
 JP> (for all I know the code may still exist),  and that it translated
 JP> C code into Lisp.

The output from the C compiler was indeed Lisp function objects,
that being the only kind of function objects on the machine.
The compiler worked by creating an intermediate representation 
called LMIL, and in the end it expanded that into Lisp code
that used DEFUN.  But it was not "normal" Lisp code, and it
relied on an extensive C execution environment.  This compiler 
was not a language translation tool -- it was a C-source-to-
machine-code-compiler, where one of the representations used in
the process was LISP (which was very close to the machine code).
I don't know if you ever got to see the Lisp code (as opposed
to the machine-code Lisp function objects).  Program debugging 
was done at the C source code level, not in Lisp.

Too bad C (also FORTRAN, ADA, and other languages) development
environments available today are not as powerful as they were 
on the Lisp Machine!