BNF vs EBNF vs ABNF:选择哪个? [英] BNF vs EBNF vs ABNF: which to choose?

查看:116
本文介绍了BNF vs EBNF vs ABNF:选择哪个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一种语言语法.我已经阅读了这三个方面的内容,但看不到一个人能做的事而另一个人却做不到的事.有什么理由要使用另一个?还是只是偏爱问题?

I want to come up with a language syntax. I have read a bit about these three, and can't really see anything that one can do that another can't. Is there any reason to use one over another? Or is it just a matter of preference?

推荐答案

您必须考虑 EBNF ABNF 作为扩展,这些扩展可以帮助您更加简洁和在发展语法时表现力强.

You have to think about EBNF and ABNF as extensions that help you just to be more concise and expressive while developing your grammars.

例如,考虑一个可选的非结束符号,在 BNF 语法中,您可以使用以下中间符号来定义它:

For example think about an optional non-terminal symbol, in a BNF grammar you would define it by using intermediate symbols like:

A        ::= OPTIONAL OTHER
OPTIONAL ::= opt_part | epsilon

在使用 EBNF 时,您可以直接使用可选语法:

while with EBNF you can do it directly using optional syntax:

A ::= [opt_part] OTHER

然后,由于无法在 BNF 中表达优先级,因此必须对嵌套选择也始终使用中间符号:

Then since there's no way to express precedence in a BNF you have to use always intermediate symbols also for nested choices:

BNF
A ::= B C
B ::= a | b | c

EBNF
A ::= (a | b | c) C

对于 EBNF ABNF 语法中允许的许多语法问题,这都是正确的,这要归功于语法糖,但不是正常的 BNF >. ABNF 扩展了 EBNF ,使您可以做更复杂的事情,例如指定可以一起找到多少个符号(即4*DIGIT)

This is true for many syntax issues that are allowed in an EBNF or ABNF grammar, thanks to syntactic sugar but not with a normal BNF. ABNF extends EBNF, allowing you to do more complicated things, like specifying how many occurrence of a symbol can be found together (i.e. 4*DIGIT)

因此,选择 ABNF EBNF 作为语法的选择语言将使您的工作更加轻松,因为在不使用无用符号填充语法的情况下,您将更具表现力无论如何,解析器生成器都会生成该文件,但是您将不会在乎它们!

So choosing an ABNF or an EBNF as language of choice for your grammar will make your work easier, since you will be more expressive without filling you grammar with useless symbols that will be generated anyway by your parser generator, but you won't care about them!

这篇关于BNF vs EBNF vs ABNF:选择哪个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆