Is there a working C++ grammar file for ANTLR?

二次信任 提交于 2019-12-04 01:57:39

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.]

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!