On Sun, 23 Feb 2003 23:10:09 +0800, lo jenny <loj...@cuhk.edu.hk> wrote:
> is there any free download software can translate C to lisp?
> Thanks
>
>
>
--
John Thingstad
KCL-derived lisps (gcl, ecl) compile lisp programs by translating
them to C.
You probably don't want to read that C, though.
Paul
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
>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.
> 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.
JP> On Sun, 23 Feb 2003 23:10:09 +0800, "lo jenny" <loj...@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!