Where can I find standard BNF or YACC grammar for C++ language?

后端 未结 6 1117
小鲜肉
小鲜肉 2021-01-30 18:00

I\'m trying to work on a kind of code generator to help unit-testing an legacy C/C++ blended project. I don\'t find any kind of independent tool can generate stub code from decl

6条回答
  •  春和景丽
    2021-01-30 18:30

    Jared's link is the closest thing to a context-free grammar you can get. Certain things do need to be delayed for later, but that is by some arguments better than the context-sensitive grammar of C++.

    To make things worse, C++1x will complexify the grammar significantly. To get as far as a perfect parse of C++, a parser will need to implement enough of the standard to correctly do overload resolution, including template argument deduction, which in turn will require the concepts mechanism, lambdas, and in effect almost all of the language, except for two-stage name lookup and exception specifications which, if I recall correctly, do not need actual implementation to parse a program successfully.

    In effect, you are halfway to a compiler if you can parse C++.

提交回复
热议问题