描述某事,我应该使用巴科斯-诺尔范式吗?
我想描述一个复杂的脚本和可能的编程语言。 我正在考虑在做任何事情之前用巴科斯-诺尔形式来描述它(不包括虚拟/示例脚本代码)
是否还有另一种形式来描述一种语言,然后是巴科斯-诺尔形式? 我应该考虑哪些替代方案?
I want to describe a complex script and possibly programming language. i was thinking of describing it in Backus-Naur Form before doing anything (excluding dummy/sample script code)
Is there another form to describe a language then Backus-Naur Form? What alternatives should i consider?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
明显的替代方案是扩展巴科斯-瑙尔形式,但是很少有其他可以使用的,我发现了一些快速搜索的链接:
Augmented BNF
Wirth 语法符号
Van Wijngaarden 语法
就我个人而言,我会坚持使用 BNF / EBNF,因为以某种形式使用它的信息和工具很流行。 bison 或 yacc 可以帮助从这样的语法生成解析器,并使生成解释器变得非常简单。
The obvious alternative would be extended Backus-Naur form, however there are few others that can be used, and I found a couple of links with some quick searching:
Augmented BNF
Wirth syntax notation
Van Wijngaarden grammar
Personally I would stick with BNF / EBNF due to the prevalence of information and tools which use it in some form. Tools like bison or yacc can help with the generation of a parser from such a grammar and make it quite trivial to produce an interpreter.
这取决于您希望描述语言的正式程度。 巴科斯-诺尔范式旨在描述上下文无关语法。 因此,如果您想描述上下文无关语法,巴科斯-诺尔范式可能是最佳选择,因为它是描述这些语法的最广泛已知的形式。
但是,如果您希望描述语义或更复杂的语法,则需要使用其他方法。 如果您还想描述语义,则需要根据语言特征(例如递归的使用)在小步语义或大步语义之间进行选择。
请注意,如果您的语法无法使用上下文无关语法来表达,那么 BNF 根本不足以表达您的语言,您可能必须考虑使用上下文相关语法来描述您的语言。
It depends on how formal you wish to describe the language. Backus-Naur Form is meant to describe context-free grammars. So if you want to describe a context-free grammar Backus-Naur Form is probably the way to go as it is the most widespread known form of describing these.
However, if you wish to describe your semantics or more complex grammars you'll need to use other means. If you want to describe your semantics as well you need to choose between small-step or big-step semantics, based on language characteristics such as use of recursion.
Note that if your grammar cant be expressed using a context-free grammar then BNF wont be sufficient to express your language at all and you might have to consider describing your language in a context-sensitive grammar.
BNF 是一个好的开始,有几个解析器生成器可以使用它作为输入。 如果您打算使用 C++,Boost.Spirit 是一个很好的例子。
BNF is a good start, there are several parser generators that can use it as input. Boost.Spirit is a good example, if you're planning to use C++.
您可能想看看 Microsoft 的“M”。 这是一种允许您描述另一种语言的语言/语法(BNF 也是如此)。 这被用作开发您自己的领域驱动语言的基础。
来自 Microsoft 的“M”
You may want to look at "M" from Microsoft. This is a language/syntax which allows you to describe another language (as does BNF). This is being used as the basis for developing your own domain driven language.
"M" from Microsoft
您还可以考虑使用 ANTLR,它使用接近 BNF 的语法/形式语言。
它将帮助您构建解释器/编译器。
You could also consider using ANTLR, which uses a syntax/formal language close to BNF.
It'll help you with the construction of a interpreter/compiler.