9

I want to write C in s-expressions and use compile-time macros. Does anybody know of anything that does this? It should translate the s-expressions into standard C.

Ollie Saunders
  • 7,787
  • 3
  • 29
  • 37
  • Could you give an example of what s-expressions you want the code to be in? vatine gave an example, but you said that it wasn't quite what you wanted. If the format doesn't matter, then could you explain why you want to write it as s-expressions? – Chip Uni Jan 14 '10 at 23:29

5 Answers5

7

Related:

Ollie Saunders
  • 7,787
  • 3
  • 29
  • 37
  • The scexp link doesn't work anymore. Use http://super.para.media.kyoto-u.ac.jp/~tasuku/sc/index.html – whoplisp Jul 12 '11 at 15:25
  • 1
    The link to kyoto-u.ac.jp isn't the same as the scexp project (It also generates C and is quite big). This is a link to scexp: http://tenkan.org/~tim/scexp-0.9.tar.gz – whoplisp Jul 12 '11 at 15:41
2

How do you mean? Something along the lines of:

(c-expression 
  (int main ((int argc) ((array (pointer char)) argv)
    (block
      (printf "%d arguments\n" argc)
      (if (argc >= 1)
        (printf "The first arg is %s\n" (ref argv 1)))
      (return 0))))
=>
"int main (int argc, char *argv[])
{
  printf("%d arguments\n", argc);
  if (argc >= 1)
    printf(The first arg is %s\n", argv[1]);
  return 0;
}

If so, yes, it's definitely doable. However, it's not entirely trivial.

Chuck
  • 234,037
  • 30
  • 302
  • 389
Vatine
  • 20,782
  • 4
  • 54
  • 70
  • 1
    Sort of like that. Although I don't think the s-expression version would look quite like some of the things you did there. – Ollie Saunders Jan 14 '10 at 16:27
2

Perhaps you want something like ECL, which compiles Common Lisp to C.

Svante
  • 50,694
  • 11
  • 78
  • 122
1

Have a look at Tasuku Hiraishi's SC. His International Lisp Conference papers from 2005 and 2007 are archived at archive.org.

See his source repo, in particular the examples.

To my knowledge that is the best of the many attempts to bring S-Expression style coding practices to bear on an otherwise vanilla C project.

Ben Hyde
  • 1,503
  • 12
  • 14
0

I know this is an old post, but for the record, I think this is what is being asked for.

The "lispc" project translates c programs written in an s-expressions style to C. It works great and even compiles the code for you if you set it up right.

I don't know that it produces the most readable C code output at the moment though.

Kyuvi
  • 360
  • 3
  • 13