简体   繁体   English

不遵循运算符关联性和优先级规则的 BNF 文法是否可以被视为明确文法?

[英]Can a BNF grammar that does not follow operator associativity and precedence rules be considered as an unambiguous grammar?

Consider this BNF grammar:考虑这个 BNF 语法:

<assign> = <id> = <expr>
<id> = A|B|C
<expr> = <id> + <expr>|<id> * <expr>|(<expr>)|<id>

This grammar is not ambiguous, since only one parse tree can be drawn for a statement.However, this clearly does not follow operator presedence rules.Operators *,+,() have the same precedence.Is this grammar unambiguous, or is it only not ambiguous?这个语法没有歧义,因为一个语句只能绘制一个解析树。但是,这显然不遵循运算符优先级规则。运算符 *,+,() 具有相同的优先级。这个语法是明确的,还是只是不模棱两可? If it is unambigious, so a grammar can be unambigious without following the operator associativity and precedence rules,is that true?如果它是明确的,那么语法可以在不遵循运算符关联性和优先级规则的情况下是明确的,这是真的吗?

"Unambiguous" and "not ambiguous" mean the exact same thing, which is that there is only one possible interpretation. “无歧义”和“不歧义”的意思完全相同,即只有一种可能的解释。 That it is not the interpretation you expect is not relevant.这不是您期望的解释是不相关的。

Is this grammar unambiguous?这个语法是明确的吗?

Yes.是的。

So a grammar can be unambigious without following the operator associativity and precedence rules,is that true?因此,如果不遵循运算符关联性和优先级规则,语法可以是明确的,这是真的吗?

Yes.是的。 Operator associativity and precedence are conventions from mathematics and programming languages.运算符关联性和优先级是数学和编程语言的约定。 Ambiguity, or lack thereof, has nothing to do with whether a grammar conforms to those conventions.歧义或缺乏歧义与语法是否符合这些约定无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM