문제

Does Augmented BNF (as specified by RFC 5234) allow matches to empty string?

From reading grammar of the Augmented BNF itself (section 4, ABNF Definition of ABNF) it seems to me that the only way is to use empty quotes (""):

empty-rule = ""

or

empty-alternative = some-rule-1 / some-rule-2 / ""

while syntax like

invalid-empty-rule = 

is not allowed.

Am I right? Why is it so?

도움이 되었습니까?

해결책

A rule with an empty right-hand side is clearly not allowed, since we have:

rule           =  rulename defined-as elements c-nl

and elements cannot match an empty sequence. (That's backed up by the actual text, which defines elements as "one or more rule names or terminal specifications".)

It appears to me that both "" and 0FOO (where FOO is any non-terminal) are legal elements, and the only possible interpretation of either of them would be an empty sequence. On the other hand, I don't believe I've ever seen either of these formulations, since it is extremely easy to indicate that an element is optional, and it is much more normal to write [NAME] than to define NAME with an alternative including an empty string.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top