C 的递归下降解析器

发布于 2024-08-12 14:33:05 字数 218 浏览 3 评论 0原文

我正在寻找 C 语言的解析器。这是我需要的:

  1. 用 C 语言(不是 C++)编写。
  2. 手写(未生成)。
  3. BSD 或类似的许可许可证。
  4. 能够非平凡地解析自身(可以是 C 的子集)。

它可以是项目的一部分,只要它是解耦的,以便我可以提取解析器。

是否有现有的解析器可以满足这些要求?

I'm looking for a parser for C. Here is what I need:

  1. Written in C (not C++).
  2. Handwritten (not generated).
  3. BSD or similarly permissive license.
  4. Capable of nontrivially parsing itself (can be a subset of C).

It can be part of a project as long as it's decoupled so that I can pull out the parser.

Is there an existing parser that fulfills these requirements?

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

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

发布评论

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

评论(8

与风相奔跑 2024-08-19 14:33:05

如果您不需要 C99,那么 lcc 就是一个灌篮:

  • 有记录在一本非常清晰、写得很好的书中。
  • Dave Hanson 的文章和技术报告中详细记录了用于优先级运算符递归下降解析的技术。
  • 清晰的手写 ANSI C 代码。

一个潜在的缺点是 lcc 解析器不会构建抽象语法树 - 它直接从解析到中间代码。

如果你必须拥有 C99 那么我认为tinycc (tcc) 是你最好的选择。

If you don't need C99, then lcc is a slam dunk:

  • It is documented in a very clear, well-written book.
  • Techniques used for recursive-descent parsing of operators with precedence are well documented in an article and technical report by Dave Hanson.
  • Clear, handwritten ANSI C code.

One potential downside is that the lcc parser does not build an abstract-syntax tree—it goes straight from parsing to intermediate code.

If you must have C99 then I think tinycc (tcc) is your best bet.

穿透光 2024-08-19 14:33:05

稀疏怎么样?

How about Sparse?

睫毛上残留的泪 2024-08-19 14:33:05

您可以尝试TCC。它是根据 Lesser GPL 获得许可的。

You could try TCC. It's licensed under the Lesser GPL.

瑶笙 2024-08-19 14:33:05

看来 nwcc 足以满足您的要求。

It seems that nwcc sufficiently agrees with your requirements.

﹉夏雨初晴づ 2024-08-19 14:33:05

良好的 C 编译器位于此位置。简单易用。
https://github.com/rui314/8cc

Good c compiler is present at this location. Simple and accessible.
https://github.com/rui314/8cc

娇妻 2024-08-19 14:33:05

GCC 在 gcc/c-parser.c 中有一个。

GCC has one in gcc/c-parser.c.

烟花易冷人易散 2024-08-19 14:33:05

检查elsa,它使用广义LR算法。

它的主要用途是针对 C++,但它也解析 C 代码。

查看其页面,名为“Elsa 可以解析多少 C?”的部分。据称它可以解析大多数 C 程序,包括 Linux 内核。

它是在 BSD 许可证下发布的。

Check elsa, it uses the Generalized LR algorithm.

Its main use is for C++, but it also parses C code.

Check on its page, on the section called "How much C can Elsa parse?" which says it can parse most C programs, including the Linux kernel.

It's released under a BSD license.

几味少女 2024-08-19 14:33:05

这是我移植到 C 的递归下降解析器:
http://www.gabotronics.com/resources/recursive-descent-parser.htm

Here is a recursive descent parser I ported to C:
http://www.gabotronics.com/resources/recursive-descent-parser.htm

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