在RFC 2141中解释NID的BNF语法

时间:2011-06-27 01:11:57

标签: regex syntax bnf ebnf urn

我无法理解BNF中的某些RFC2141语法。

该行为<NID> ::= <let-num> [ 1,31<let-num-hyp> ]。我认为这意味着<NID>是字符串的符号,受两个规则的约束:

  1. 该字符串必须以<let-num>个字符的任何一个出现。
  2. 此字符后面可能跟随任何<let-num-hyp>字符的0-31次出现*。
  3. 我是否正确阅读?因为,如果是的话,其中一些含义会让人感到困惑。

    * 相当于“可选,1-31次出现

    RFC2141<NID>(命名空间标识符)的完整BNF语法为:

    <NID>         ::= <let-num> [ 1,31<let-num-hyp> ]
    <let-num-hyp> ::= <upper> | <lower> | <number> | "-"
    <let-num>     ::= <upper> | <lower> | <number>
    <upper>       ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" |
                      "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" |
                      "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" |
                      "Y" | "Z"
    <lower>       ::= "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" |
                      "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" |
                      "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" |
                      "y" | "z"
    <number>      ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
                      "8" | "9"
    

1 个答案:

答案 0 :(得分:2)

你已经正确地解释了它。有什么令人困惑的含义?

<NID> ::= <let-num> [ 1,31<let-num-hyp> ]

表示出现<let-num>一次,最多可出现31次出现<let-num-hyp>

考虑到其他定义,这意味着一个至少包含一个字符且最多32个字符的字符串,由大小写,数字和连字符组成,第一个字符不允许是连字符。