简体   繁体   English

如何在BNF中表示Java样式的OR?

[英]how to represent Java-style OR in BNF?

Good day. 美好的一天。 I was wondering, if I wanted to do a Backus-Naur form representing for example an if-else clause in Java, how would I go about using OR and AND for multiple conditions? 我想知道,如果我想做一个表示Java中if-else子句的Backus-Naur表单,我该如何在多个条件下使用OR和AND? I know that AND can be simply represented with &&, and OR with ||. 我知道AND可以简单地用&&表示,或用||表示。 But as vertical lines are already part of BNF syntax, I would like to know if this is allowed anyways. 但是由于垂直线已经是BNF语法的一部分,所以我想知道是否仍然允许这样做。

From: https://users-cs.au.dk/amoeller/RegAut/JavaBNF.html 来自: https : //users-cs.au.dk/amoeller/RegAut/JavaBNF.html

<conditional or expression> ::= <conditional and expression> | <conditional or expression> || <conditional and expression>

<conditional and expression> ::= <inclusive or expression> | <conditional and expression> && <inclusive or expression>

Logical or is pretty unambiguous because you have two || 逻辑还是很明确,因为您有两个|| , but you can always represent literals in bold, or another font or quotes. ,但是您始终可以用粗体,其他字体或引号来表示文字。

Another example here: https://users-cs.au.dk/amoeller/RegAut/JavaBNF.html uses bold and a fixed width font for literals. 此处的另一个示例: https : //users-cs.au.dk/amoeller/RegAut/JavaBNF.html对文字使用粗体和固定宽度的字体。

Wiki shows quotes which is safest if you don't have multiple fonts available: Wiki显示引号,如果您没有可用的多种字体,这是最安全的:

<expression> ::= <list> | <list> <opt-whitespace> "|" <opt-whitespace> <expression>

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

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