第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. ; 注释
分号表示注释, 从分号的位置到行尾都是注释. 如果某行以分号开头,表示整行
都是注释. 这是一个在定义中包含有用信息的好方法
--------------------------------------------------------------------------------------------------------------------------------------