将 C 写为 s 表达式

发布于 2024-08-17 15:55:01 字数 64 浏览 2 评论 0原文

我想在 s 表达式中编写 C 并使用编译时宏。有人知道有什么可以做到这一点吗?它应该将 s 表达式翻译成标准 C。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

兮颜 2024-08-24 15:55:01

也许您想要类似 ECL 的东西,它将 Common Lisp 编译为 C。

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

不奢求什么 2024-08-24 15:55:01

你是什​​么意思?大致意思是:

(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;
}

如果是这样,是的,这绝对是可行的。然而,这并不完全是微不足道的。

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.

柠檬色的秋千 2024-08-24 15:55:01

看看平石佑的 SC。他的国际 Lisp 会议论文来自 20052007 存档于 archive.org。

请参阅他的源代码库,特别是示例

据我所知,这是将 S-Expression 风格的编码实践应用于普通 C 项目的众多尝试中最好的一次。

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.

划一舟意中人 2024-08-24 15:55:01

我知道这是一篇旧帖子,但为了记录,我认为这就是所要求的。

“lispc”项目将以 s 表达式风格编写的 C 程序转换为 C 语言。它工作得很好,而且如果您设置正确,甚至可以为您编译代码。

但我不知道它是否会产生目前最可读的 C 代码输出。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文