开发者

Write C as s-expressions

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 st开发者_如何学Pythonandard C.


  • http://voodoo-slide.blogspot.com/2010/01/amplifying-c.html
  • http://www.unmutual.info/software/scexp/

Related:

  • http://news.ycombinator.com/item?id=1071222
  • http://www.thinlisp.org/whitepaper.html
  • http://www.bitc-lang.org/
  • http://en.wikipedia.org/wiki/PreScheme
  • http://neontology.com/posts/2007/08/11/whats-nu


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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜