From: ·············@my-deja.com
Subject: Lisp code that writes non-lisp code
Date: 
Message-ID: <92vr8r$g4h$1@nnrp1.deja.com>
Hi!

	Where can I find some samples of  Lisp used to generate source
code of another language?  I need to use a very limited and buggy
language(no functions, limited loops) and I definitely don't want to
deal directly with it....


Sent via Deja.com
http://www.deja.com/

From: Stig Hemmer
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <ekvlmssxxbw.fsf@verden.pvv.ntnu.no>
·············@my-deja.com writes:
> 	Where can I find some samples of  Lisp used to generate source
> code of another language?

Well, CLISP generates C code that it passes to the C compiler.  I have
no idea how readable that code is though.

Stig Hemmer,
Jack of a Few Trades.
From: Stig Hemmer
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <ekvae97dq8b.fsf@verden.pvv.ntnu.no>
Stig Hemmer <····@pvv.ntnu.no> writes:
> Well, CLISP generates C code that it passes to the C compiler.

I have been informed by email that this is not the case.  Sorry about
the misinformation.

Stig Hemmer,
Jack of a Few Trades.
From: glauber
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <930fsc$385$1@nnrp1.deja.com>
In article <············@nnrp1.deja.com>,
  ·············@my-deja.com wrote:
> Hi!
>
> 	Where can I find some samples of  Lisp used to generate source
> code of another language?  I need to use a very limited and buggy
> language(no functions, limited loops) and I definitely don't want to
> deal directly with it....


You mean something like this?

(defparameter outf (make-pathname :name "hello" :type "c"))

(defvar cprog '("#include <stdio.h>"
                "#include <stdlib.h>"
                "int main (int argc, char ** argv)"
                "{"
                "    puts(\"Hello World!\");"
                "    return 0;"
                "}"))

(with-open-file (cfile outf :direction :output :if-exists :supersede)
  (dolist (cline cprog)
          (format cfile "~a~%" cline)))



This code fragment generates a C program, but the same approach
should work for most computer languages!

(Note: use of this or any other technique to generate Visual Basic
is considered in bad taste.)

:-) :-) :-)


--
Glauber Ribeiro
··········@my-deja.com    http://www.myvehiclehistoryreport.com
"Opinions stated are my own and not representative of Experian"


Sent via Deja.com
http://www.deja.com/
From: Rainer Joswig
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <joswig-066F4E.01434004012001@news.is-europe.net>
In article <············@nnrp1.deja.com>, glauber 
<··········@my-deja.com> wrote:

> In article <············@nnrp1.deja.com>,
>   ·············@my-deja.com wrote:
> > Hi!
> >
> > 	Where can I find some samples of  Lisp used to generate source
> > code of another language?  I need to use a very limited and buggy
> > language(no functions, limited loops) and I definitely don't want to
> > deal directly with it....

Look for example in the CMU Lisp archive for PLisp.
Postscript in Lisp.

Rainer Joswig

-- 
Rainer Joswig, Hamburg, Germany
Email: ·············@corporate-world.lisp.de
Web: http://corporate-world.lisp.de/
From: Geoffrey Summerhayes
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <vzT46.22462$n%.1140975@news20.bellglobal.com>
"glauber" <··········@my-deja.com> wrote in message
·················@nnrp1.deja.com...
> (Note: use of this or any other technique to generate Visual Basic
> is considered in bad taste.)

Including Visual Studio, etc.
The one joy I get from using VC++ 1.5 at work is the fact that the rest of
them use VB 6 ;-)

Geoff

"Hell is in Hello" <Paint your Wagon>
From: thi
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <y167l4bjhlr.fsf@glug.org>
glauber <··········@my-deja.com> writes:

> In article <············@nnrp1.deja.com>,
>   ·············@my-deja.com wrote:
> > Hi!
> >
> > 	Where can I find some samples of  Lisp used to generate source
> > code of another language?  I need to use a very limited and buggy
> > language(no functions, limited loops) and I definitely don't want to
> > deal directly with it....
> 
> You mean something like this?
> 
> (defparameter outf (make-pathname :name "hello" :type "c"))
> 
> (defvar cprog '("#include <stdio.h>"
>                 "#include <stdlib.h>"
>                 "int main (int argc, char ** argv)"
>                 "{"
>                 "    puts(\"Hello World!\");"
>                 "    return 0;"
>                 "}"))
> 
> (with-open-file (cfile outf :direction :output :if-exists :supersede)
>   (dolist (cline cprog)
>           (format cfile "~a~%" cline)))

for a shamelessly ugly example of producing swig-able interface
definition files from C++ code using Emacs lisp, check out:

  http://www.scripps.edu/~ttnttn/build/mead/swig/swigpp.el

the rest of the directory has related cruft.

thi
From: ········@hex.net
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <eIQ46.198741$DG3.4496737@news2.giganews.com>
·············@my-deja.com writes:
> 	Where can I find some samples of  Lisp used to generate source
> code of another language?  I need to use a very limited and buggy
> language(no functions, limited loops) and I definitely don't want to
> deal directly with it....

Hmm...

Here's a chunk of Scheme I use to generate fancy "selection screens"
in ABAP/4.  It would be an easy port to CL...

;;; This code generates selection screens
;;; for dates.

(define 
  (generate-block prefix longname textid)
  (newline)
  (display "* Selection block for parameters:") (newline)
  (display (string-append 
	    "* Generated by genselect.scm (generate-block \"" 
	    prefix "\" \"" 
	    longname "\" "
	    (number->string textid) ")"))
  (newline)
  
  (display "selection-screen begin of line.") (newline)
  (display (string-append "selection-screen comment 1(10) "
			  (text-element-string  textid) 
			  "."))
  (newline)
  (newline)

;; Now generate individual lines

  (let ((entries '("1st" "2nd" "3rd" "4th" "Last" "All")))
    (let loop
	((pos 15)
	 (textelement 2)
	 (item 1)
	 (textlst entries))
      (if (> (length textlst) 0)
	  (let* ((titem (car textlst))
		 (itemlen (string-length titem)))
	    (genentry prefix pos textelement item itemlen)
	    (loop (+ pos itemlen 3) 
		  (+ textelement 1)
		  (+ item 1)
		  (cdr textlst))))))
  
;  (genentry prefix 15 2 1 3)   ; 1st
;  (genentry prefix 22 3 2 3)   ; 2nd
;  (genentry prefix 28 4 3 3)  ; 3rd
;  (genentry prefix 34 5 4 3)  ; 4rd
;  (genentry prefix 40 6 5 4)  ; last
;  (genentry prefix 47 7 6 3)  ; All
  
  (display "selection-screen end of line.")
  (newline)
					
;  (display 
;     (string-append "selection-screen end of block " 
;		    longname
;		    ".")))
)

(define (text-element-string elementno)
  (string-append 
   "text-"
   (cond
    ((> 10 elementno) "00")
    ((> 100 elementno) "0")
    ((> 1000 elementno) ""))
   (number->string elementno)))

(define (genentry prefix pos textelement item size)
  (display 
   (string-append "  selection-screen comment "
		  (number->string pos)
		  "("  (number->string size) 
		  ") "
		  (text-element-string textelement)
		  "."))
  (newline)
  (display
   (string-append "  parameters: "
		  prefix
		  (number->string item)
		  " as checkbox."))
  (newline))

(define (move-to-struct prefix struct val)
  (newline)(display  (string-append
	     "* Set up structure "
	     struct
	     " for prefix "
	     prefix))
  (newline)
  (display (string-append 
	    "* Generated by genselect.scm (move-to-struct \"" prefix  "\" \""
	    struct "\")"))
  (newline)
  
  (let ((fulllst '(1 2 3 4 5 6))
	(doitem (lambda (num)
		  (display 
		     (string-append 
		      " "
		      prefix (number->string num))))))
    (display "  perform vars_to_week_struct using ")
    (for-each doitem fulllst)
    (newline)
    (display (string-append "       " (number->string val)))
    (newline)
    (display (string-append "            changing " struct "."))
    newline))

(define (display-struct-setter)
  (newline)  
  (display "form vars_to_week_struct ") (newline)
  (display "    using FIRST SECOND THIRD FOURTH LAST ALL VAL") (newline)
  (display "    changing WEEK_STRUCT like sun.") (newline)
  (display "  week_struct-first = first.") (newline)
  (display "  week_struct-second = second.") (newline)
  (display "  week_struct-third = third.") (newline)
  (display "  week_struct-fourth = fourth.") (newline)
  (display "  week_struct-last = last.") (newline)
  (display "  week_struct-all = all.") (newline)
  (display "  week_struct-val = val.") (newline)
  (display "endform.") (newline))


;;; Now, let's go generate some code:

;;;(generate-block prefix longname textid)
;;;(move-to-struct prefix struct)

(display "selection-screen begin of block WeekInfo") (newline)
(display "with frame title text-020.") (newline)
(generate-block "suns" "Sunday" 1)
(generate-block "mons" "Monday" 8)
(generate-block "tues" "Tuesday" 9)
(generate-block "weds" "Wednesday" 10)
(generate-block "thus" "Thursday" 11)
(generate-block "fris" "Friday" 12)
(generate-block "sats" "Saturday" 13)
(newline)
(display "selection-screen end of block WeekInfo.") (newline)
;(display "form collect_vars_into_structs.")
;(newline)
;(move-to-struct "SUNS" "SUN" 0)
;(move-to-struct "MONS" "MON" 1)
;(move-to-struct "TUES" "TUE" 2)
;(move-to-struct "WEDS" "WED" 3)
;(move-to-struct "THUS" "THU" 4)
;(move-to-struct "FRIS" "FRI" 5)
;(move-to-struct "SATS" "SAT" 6)
; (newline)
; (display "endform.")
; (newline)
; (display-struct-setter)

-- 
(reverse (concatenate 'string ····················@" "454aa"))
<http://www.ntlug.org/~cbbrowne/>
Rules of the Evil Overlord #31. "All naive, busty tavern wenches in my
realm  will be replaced  with surly,  world-weary waitresses  who will
provide no  unexpected reinforcement  and/or romantic subplot  for the
hero or his sidekick." <http://www.eviloverlord.com/>
From: Reini Urban
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <3a5444cd.1819361924@judy>
·············@my-deja.com wrote:
>	Where can I find some samples of  Lisp used to generate source
>code of another language?  I need to use a very limited and buggy
>language(no functions, limited loops) and I definitely don't want to
>deal directly with it....

* gambit
* bigloo
* rs (compiler/cgen/)
* MIT scheme (LIAR in src/compiler/machines/C)
* ffigen

write all C.

most better lisp compilers write machine code directly, the others at
least the VM bytecode, which is similar. (see the appropriate compiler
directories)

-- 
Reini Urban
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
From: Anders Vinjar
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <coppui3pfub.fsf@clara.uio.no>
>>> "RU" == Reini Urban <······@sbox.tu-graz.ac.at> writes:
    >> Where can I find some samples of Lisp used to generate
    >> source code of another language?  I need to use a very
    >> limited and buggy language(no functions, limited loops)
    >> and I definitely don't want to deal directly with it....

CLM and CMN are Lisp-based computer-music applications which has
built in transcription to C and Postscript as part of their
(respective) functionality.

Sources and docs are available at CCRMA:

  http://ccrma-www.stanford.edu/software/
From: Paolo Amoroso
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <+mxUOruq9b+cWKHBLJEAyYzpq0Zl@4ax.com>
On Wed, 03 Jan 2001 18:32:59 GMT, ·············@my-deja.com wrote:

> 	Where can I find some samples of  Lisp used to generate source
> code of another language?  I need to use a very limited and buggy

You might check some HTML generators written in Lisp. Here are some places
where you can find such code:

  Web section of CLiki
  http://ww.telent.net/cliki/

  cllib, which is part of CLOCC (Common Lisp Open Code Collection)
  http://sourceforge.net/projects/clocc

  CL-HTTP
  http://www.ai.mit.edu/projects/iiip/doc/cl-http/home-page.html


Paolo
-- 
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/
From: Jim White
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <JU166.355530$3E6.5198006@news1.alsv1.occa.home.com>
<·············@my-deja.com> wrote in message
·················@nnrp1.deja.com...
> Where can I find some samples of  Lisp used to generate source
> code of another language?  I need to use a very limited and buggy
> language(no functions, limited loops) and I definitely don't want to
> deal directly with it....

Aubrey Jaffer's Schlep is a nifty tool which generates C:

http://www-swiss.ai.mit.edu/~jaffer/scm95-2.html

jim
------------------------------------------------------------
James P. White             Netscape DevEdge Champion for IFC
IFC Exchange  -  Insanely great Java  -  http://www.ifcx.org
From: Rob Warnock
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <93be31$lkcsc$1@fido.engr.sgi.com>
Jim White <···@pagesmiths.com> wrote:
+---------------
| Aubrey Jaffer's Schlep is a nifty tool which generates C:
| http://www-swiss.ai.mit.edu/~jaffer/scm95-2.html
+---------------

It is nifty, especially the way it preserves top-level comments and
the care with which it tries to output well-formatted C. As Aubrey said,

  "Most programmers I work with are not fluent in Scheme and they
  have to be able to understand my code contributions."

But... After trying to work with it for a while, I just couldn't get
comfortable with the Hungarian (or is it reverse-Hungarian?) he uses
for typing. [Schlep looks at the last few characters of identifiers
and maps them to a C type.]  I tried adding CL-style declaim/declare
to it, and *sort of* got it working, but ran out of steam.

[I also tried adding "defmacro", so I could do repetitive coding at a
higher level, as well as compile-time meta-coding, and was again only
partially successful.]

Still, it's well worth studying/using/hacking-on if it's anywhere near
"close enough" to what you need...


-Rob

p.s. IMHO, Schlep is not so much "a" program as a particular *pattern*
for writing Scheme/Lisp->C translators. That is, it's very much a
"habitable" environment [in the Alexander/Gabriel sense]. One is
*expected* to hack on it here & there to fit the task at hand.
(And indeed, if you grab snapshots of it from Jaffer's site, you'll
see that it mutates from time to time as he adds little additional
pieces for this task or that.)

Other, different patterns for similar thing may be found, say, in
MzScheme's wrapper for a "libguile" implementation, in particular the
file "plt/src/mzscheme/guile/mkghsrc" in the MzScheme source distribution,
which is almost trivial compared to Schlep, but is "good enough" to build
several dozen wrapper procedures in C. It too is worth studying, if only
to see how simply such things can be done in restricted applications.

-----
Rob Warnock, 31-2-510		····@sgi.com
SGI Network Engineering		http://reality.sgi.com/rpw3/
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA
From: Marco Antoniotti
Subject: Re: Lisp code that writes non-lisp code
Date: 
Message-ID: <y6c8zomngea.fsf@octagon.mrl.nyu.edu>
As an aside, I must say that the key to writing nice "source-2-source"
translators is the availability of a pretty-print package.

I ended up rewriting most of CL pretty printer in Java (translating
from CMUCL PPRINT stuff) for a translator project that had to generate
code in Java, C, and Esterel.

It is kinda clunky (given that in Java you do not have macros), but
it works nicely.  Anybody interested, send me email.

Cheers

-- 
Marco Antoniotti =============================================================
NYU Bioinformatics Group			 tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                          fax  +1 - 212 - 995 4122
New York, NY 10003, USA				 http://galt.mrl.nyu.edu/valis
             Like DNA, such a language [Lisp] does not go out of style.
			      Paul Graham, ANSI Common Lisp