C 的递归下降解析器
我正在寻找 C 语言的解析器。这是我需要的:
- 用 C 语言(不是 C++)编写。
- 手写(未生成)。
- BSD 或类似的许可许可证。
- 能够非平凡地解析自身(可以是 C 的子集)。
它可以是项目的一部分,只要它是解耦的,以便我可以提取解析器。
是否有现有的解析器可以满足这些要求?
I'm looking for a parser for C. Here is what I need:
- Written in C (not C++).
- Handwritten (not generated).
- BSD or similarly permissive license.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如果您不需要 C99,那么 lcc 就是一个灌篮:
一个潜在的缺点是 lcc 解析器不会构建抽象语法树 - 它直接从解析到中间代码。
如果你必须拥有 C99 那么我认为tinycc (tcc) 是你最好的选择。
If you don't need C99, then lcc is a slam dunk:
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.
稀疏怎么样?
How about Sparse?
您可以尝试TCC。它是根据 Lesser GPL 获得许可的。
You could try TCC. It's licensed under the Lesser GPL.
看来 nwcc 足以满足您的要求。
It seems that nwcc sufficiently agrees with your requirements.
良好的 C 编译器位于此位置。简单易用。
https://github.com/rui314/8cc
Good c compiler is present at this location. Simple and accessible.
https://github.com/rui314/8cc
GCC 在 gcc/c-parser.c 中有一个。
GCC has one in gcc/c-parser.c.
检查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.
这是我移植到 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