是否有工作的 C++ ANTLR 的语法文件?
ANTLR 是否有现有的 C++ 语法文件?
我正在寻找 lex,而不是解析一些 C++ 源代码文件。
我查看了 ANTLR 语法页面,看起来有一个由 Sun Microsystems 创建的列表此处。
然而,它似乎是一个生成的解析器。
谁能给我指出一个 C++ ANTLR 词法分析器或语法文件?
Are there any existing C++ grammar files for ANTLR?
I'm looking to lex, not parse some C++ source code files.
I've looked on the ANTLR grammar page and it looks like there is one listed created by Sun Microsystems here.
However, it seems to be a generated Parser.
Can anyone point me to a C++ ANTLR lexer or grammar file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
C++ 解析器很难构建。
我无法谈论使用 ANTLR 的 C++ 语法的经验。 在这里,我讨论我通过阅读我在 ANTLR 网站上看到的注释所附的注释学到了什么;本质上,作者创造了一个不完整的语法。这仅适用于 C++98。我已经有一段时间没看过了;可能还有其他人。
我们的DMS 软件再工程工具包有一个强大的 C++ 前端。
词法分析器处理 ANSI、GCC3、MS Visual Studio 2008 的所有问题,包括大精度浮点数等。
[编辑:12/2011。现在处理 C++11 和 OpenMP 指令]
[编辑:3/2015:现在处理 GCC 和 MS 变体中的 C++14。
在此处查看一些解析树]
“仅”有一个解析器实际上并不是很有用。除了“只是解析”之外,我们的前端还将构建 AST、构建准确的符号表(对于 C++ 来说,这是极其困难的)、执行函数局部流分析,并允许您执行程序转换等。请参阅解析后的生活。
[编辑:5/2019:现在处理 ANSI、GCC 和 MS 变体中的 C++17。跨编译单元完成名称和类型解析。用于自动化大规模神级重构/分割 3000个编译单元的系统。]
C++ parsers are tough to build.
I can't speak with experience about using ANTLR's C++ grammars. Here I discuss what I learned by reading the notes attached to the the one I did see at the ANTLR site; in essence, the author produced an incomplete grammar. And that was for just C++98. It has been awhile since I looked; there may be others.
Our DMS Software Reengineering Toolkit has a robust C++ front end.
The lexer handles all the cruft for ANSI, GCC3, MS Visual Studio 2008, including large-precision floating point numbers, etc.
[EDIT: 12/2011. Now handles C++11 and OpenMP directives]
[EDIT: 3/2015: Now handles C++14 in both GCC and MS variants.
See some parse trees here on SO]
Having "just" a parser is actually not very useful. Above and beyond "just parsing", our front end will build ASTs, build accurate symbol tables (for C++, this is extremely hard to do), perform function-local flow analysis, and allow you to carry out program transformations, etc. See Life After Parsing.
[EDIT: 5/2019: Now handles C++17 in ANSI, GCC and MS variants. Does complete name and type resolution across compilation units. Used to automate large scale God-class refactoring/splitting across systems of 3000 compilation units.]