RFC 822 中文版 MIME解析基礎(3)(第3-4頁)

第3頁

--------------------------------------------------------------------------------------------------------------------------------------
     2.  NOTATIONAL CONVENTIONS

          This specification uses an augmented Backus-Naur Form  (BNF)
     notation.  The differences from standard BNF involve naming rules
     and indicating repetition and "local" alternatives.

     2.1.  RULE NAMING

          Angle brackets ("<", ">") are not  used,  in  general.   The
     name  of  a rule is simply the name itself, rather than "<name>".
     Quotation-marks enclose literal text (which may be  upper  and/or
     lower  case).   Certain  basic  rules  are  in uppercase, such as
     SPACE, TAB, CRLF, DIGIT, ALPHA, etc.  Angle brackets are used  in
     rule  definitions,  and  in  the rest of this  document, whenever
     their presence will facilitate discerning the use of rule names.

     2.2.  RULE1 / RULE2:  ALTERNATIVES

          Elements separated by slash ("/") are alternatives.   There-
     fore "foo / bar" will accept foo or bar.

     2.3.  (RULE1 RULE2):  LOCAL ALTERNATIVES

          Elements enclosed in parentheses are  treated  as  a  single
     element.   Thus,  "(elem  (foo  /  bar)  elem)"  allows the token
     sequences "elem foo elem" and "elem bar elem".

     2.4.  *RULE:  REPETITION

          The character "*" preceding an element indicates repetition.
     The full form is:

                              <l>*<m>element

     indicating at least <l> and at most <m> occurrences  of  element.
     Default values are 0 and infinity so that "*(element)" allows any
     number, including zero; "1*element" requires at  least  one;  and
     "1*2element" allows one or two.

     2.5.  [RULE]:  OPTIONAL

          Square brackets enclose optional elements; "[foo  bar]"   is
     equivalent to "*1(foo bar)".

     2.6.  NRULE:  SPECIFIC REPETITION

          "<n>(element)" is equivalent to "<n>*<n>(element)"; that is,
     exactly  <n>  occurrences  of (element). Thus 2DIGIT is a 2-digit
     number, and 3ALPHA is a string of three alphabetic characters.

--------------------------------------------------------------------------------------------------------------------------------------
     2.  符號約定

          本標準使用了一種擴展的巴克斯範式(BNF)。本標準的範式定義和標準
     的BNF的差別主要包括:命名規則,重複標誌和一些局部變動。
         

     2.1.  命令規則

          通常,尖括號("<", ">")沒有使用。一個規則的名字僅僅是名字本身,
     而不是"<名字>"。引號包含合法文本( 它們可能是大寫或者小寫 ).有幾個
     基本的定義使用了大寫,比如SPACE, TAB, CRLF, DIGIT, ALPHA等等.在下面
     的規則定義中,會用尖括號, 它們將有助於我們明確規則名.
    

     2.2.  規則1 / 規則2:  可選的

          用斜槓("/")分開的元素,表示可選. 例如:
          "foo / bar"表示foo和bar都滿足條件.
         
     2.3.  (規則1 規則2):  局部可選

          用圓括號包起來的多個元素,被認爲是一個元素. 例如:
          "(elem  (foo  /  bar)  elem)"
          可以是"elem foo elem",也可以是"elem bar elem"

     2.4.  *規則:  重複

          星號 "*" 代表星號之後的一個元素的重複. 完整的語法是
         
             <最小次數>*<最大次數>元素
         
          代表元素被重複至少<最小次數>次,最多<最大次數>次,<最小次數>和
     <最大次數>都可以沒有,如果沒有, 默認值分別是0和無窮大. 這樣"*(元素)",
     代表了元素被重複0到任意多次. "1*(元素)"代表元素被重複1到任意次,
     "1*2(元素)"代表重複一次或者兩次.

     2.5.  [規則]:  可選

          方括號裏的元素, 表示可有可無, "[foo bar]" 等價於 "*1(foo bar)"

     2.6.  帶個數的重複:  指定次數的重複

          "<n>(元素)" 等價於 "<n>*<n>(元素)", 表示元素被重複n次, 例如:
          2DIGIT,表示2個數字,3ALPHA表示3個字母.

--------------------------------------------------------------------------------------------------------------------------------------

第4頁

--------------------------------------------------------------------------------------------------------------------------------------
     2.7.  #RULE:  LISTS

          A construct "#" is defined, similar to "*", as follows:

                              <l>#<m>element

     indicating at least <l> and at most <m> elements, each  separated
     by  one  or more commas (","). This makes the usual form of lists
     very easy; a rule such as '(element *("," element))' can be shown
     as  "1#element".   Wherever this construct is used, null elements
     are allowed, but do not  contribute  to  the  count  of  elements
     present.   That  is,  "(element),,(element)"  is  permitted,  but
     counts as only two elements.  Therefore, where at least one  ele-
     ment  is required, at least one non-null element must be present.
     Default values are 0 and infinity so that "#(element)" allows any
     number,  including  zero;  "1#element" requires at least one; and
     "1#2element" allows one or two.

     2.8.  ; COMMENTS

          A semi-colon, set off some distance to  the  right  of  rule
     text,  starts  a comment that continues to the end of line.  This
     is a simple way of including useful notes in  parallel  with  the
     specifications.

 

--------------------------------------------------------------------------------------------------------------------------------------


    2.7.  #規則:  列表


          "#"類似"*",它的語法如下:
                 <最小次數>#<最大次數>元素

      代表元素被重複至少<最小次數>次,最多<最大次數>次,<最小次數>和
     <最大次數>都可以沒有,如果沒有, 默認值分別是0和無窮大
    
     #規則也*規則的不同在於, 各個元素之間用一個或多個逗號(",")隔開.
     這個規則讓表達一個列表非常容易; 如下:
      '(元素 *("," 元素))' 也可以寫成
      "1#元素"
      
     #規則使用時,允許空元素,但是空元素不計算個數. 就是說"(元素),,(元素)"
     是允許的,但是它只有兩個元素. 在下面的描述中,如果說至少需要一個元素,
     是說至少需要一個非空元素.
  "1#元素"表示一個任意多個元素
  "1#2元素"代表一個或兩個元素
        
     2.8.  ; 註釋

          分號表示註釋, 從分號的位置到行尾都是註釋. 如果某行以分號開頭,表示整行
     都是註釋. 這是一個在定義中包含有用信息的好方法
    
    
--------------------------------------------------------------------------------------------------------------------------------------

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章