'Empty productions in RFC 5234 (Augmented BNF)
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?
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | rici |