Question

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.

OTHER TIPS

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

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.

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.

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

This 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top