Subject: Re: S-expr form of C
From: rpw3@rpw3.org (Rob Warnock)
Date: Fri, 31 Oct 2008 23:29:56 -0500
Newsgroups: comp.lang.lisp
Message-ID: <A5SdneRY_5LZRpbUnZ2dnUVZ_gCdnZ2d@speakeasy.net>
Pascal Bourguignon  <pjb@informatimago.com> wrote:
+---------------
| Rob Warnock wrote:
| > I'd like to ask the inverse of this, namely, is there any
| > generally-accepted "best style" in the Lisp community for
| > representing C source code in s-expr form? ... I'm more looking
| > for a more literal "representation" of C source in s-expr form,
| > with a view towards writing a sort of "LAP" which targets C,
| > with the ability to wrap CL macros around the "LAP". Anybody
| > got any pointers to prior art?
| 
| In my own S-exp to C system, the objective is to be able to generate 
| (almost) all the possible C/C++ syntax from S-exp.  I actually generate 
| it from CLOS objects, and have macros defined to build these CLOS 
| objects from the corresponding S-exp.
| 
| But this is only the lowest level of that system.  (You could call it 
| "CLAP", for "C Level Assembler Program").
+---------------

Well, being a networking/datacomms kind of guy myself, I tend to
call it "LAP-C". [There's a bad pun in there for old datacomm types].
But, yes. That's exactly what I'm looking for. Are you willing to
share your surface syntax/notation? Or at least its general shape?
[Wraps everything in type specifiers? Uses CL-style declarations?
Uses lookaside tables of name->type pattern matches? Other?]

+---------------
| Right away, I implement a macro system and progressively implement
| more and more of Common Lisp-alike features, generating C code.
| Soon enough we don't write (for ...) loops, but dotime or dolist loops...
| 
| So there's not much point in having a "generally-accepted best style" 
| for this kind of things, since with macros you will develop your own DSL 
| anyways.
+---------------

I do, in fact, understand your point, but I still believe it's best
to ground such an effort firmly in some concrete syntax which *can*
"generate (almost) all the possible C/C++ syntax from S-exp", rather
than hack around with a quick&dirty syntax (such as the ones I showed
before) for a long time only to find that you have to completely re-do
your whole system because you left out something fundamental from the
concrete syntax. It was for that reason that I asked the question in
the first place -- trying to get a leg up by learning from others'
mistakes without having to re-make all of them myself!  ;-}


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607