帕斯卡风格铁路图

发布于 2024-07-09 09:54:43 字数 56 浏览 9 评论 0原文

在哪里可以找到 pascal 风格的铁路图来描述 C++ 语法? (作为 EBNF 的替代方案)

Where can I find pascal-style railroad diagrams to describe C++ syntax?
(As an alternative to EBNF)

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

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

发布评论

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

评论(3

慈悲佛祖 2024-07-16 09:54:43

据我所知,不存在。 C++ 语法甚至不能用正确的 EBNF 来表达 - 它是上下文相关的语法,任何试图解析它的东西都必须能够处理 C++ 代码,至少在模板实例化和重载解析方面(更不用说宏了) )。

There don't exist any, as far as I know. The C++ syntax can't even be expressed in a proper EBNF - it's a context-sensitive grammar, and anything attempting to parse it has to be capable of processing C++ code at least as far as template instantiation and overload resolution (not to mention macros).

土豪我们做朋友吧 2024-07-16 09:54:43

不存在 - C++ 语法不仅不是上下文无关,而且是不可判定的。 请参阅http://yosefk.com/c++fqa/defective.html#defect-2 以及相关链接更深入的讨论。

There isn't one - the C++ grammar is not only not context-free, it's undecidable. See http://yosefk.com/c++fqa/defective.html#defect-2 and the associated links for a more in-depth discussion.

泛滥成性 2024-07-16 09:54:43

我不知道是否有一些 C++ 图的铁路图(我不太看重这些图像),但将 EBNF 转换为这些图纯粹是机械工作。

关于C++的语法:如果你看一下C++标准附录中的语法,那就是上下文无关语法。 该语法的问题在于它是一种二义性语法。 另一件事是,语法接受不是有效 C++ 程序的字符串 - 但这对于带有变量声明的每种类型语言都是如此。 如果语法是不可判定,则意味着您无法判断某个字符串是否是根据语法生成的。 顺便说一句,给定的 C++ 文件能否编译确实是一个不可判定的问题,因为模板是图灵完备的。

这种模棱两可的语法不受欢迎的原因是它使解析器变得更加复杂、更慢和/或需要更多内存。

I don't know if there are some railroad diagrams for the C++ diagrams (I don't value these image much) but it is a purely mechanical work to transform EBNF to these diagrams.

About the grammar of C++: If you look at the grammar in the appendix of the C++ standard, that is a context-free grammar. The problem with this grammar is that it is an ambiguous grammar. Another thing is, the grammar accepts strings that are not valid C++ programs - but this is true about every typed languages with variable declarations. If the gramar was undecidable, it would mean that you could not tell for some string if it was generated according to the grammar or not. BTW, it really is undecidable problem whether given C++ file compiles, because templates are Turing-complete.

The reason why this ambiguous grammar is frowned upon is that it makes the parser much more complex, slower and/or needing more memory.

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