EBNF实例讲解(翻译自Extended BNF. ISO/IEC 14977 : 1996(E))

实在是资料太少了,这作业写得我要死了。
资料都是英文的,我觉得直接看例子比较容易懂。
话不多说上例子了。

4.22 Further examples

The following example is a syntax-rule that states that a Fortran 77 continuation line starts with 5 blanks, the sixth character must not be a blank or zero, and there must not be more than 72 (= 5+1+66) characters altogether.

Fortran 77 continuation line=5*" “, (character - (” " | “0”)), 66 * [character] ;

In Fortran 66, the definition of a continuation line is more complicated. The following example is a syntax-rule that states that a continuation line must not start with C, there must be at least 6 characters, the sixth character must not be a blank or zero, and there must not be more than 72 (= 1+4+1+66) characters altogether.

Fortran 66 continuation line = character - “C”, 4 * character, character - (" " | “0”),
66 * [character] ;
下面的例子是一个语法规则,规定Fortran 77的延续行以5个空行开始,第6个字符不能是空行或0,并且总共不能超过72个字符(=5+1+66)。
Fortran 77延续行=5
" “, (字符 - (” " | “0”)), 66 * [字符] ;
在Fortran 66中,延续行的定义比较复杂。下面的例子是一个语法规则,它规定了一个延续行不能以C开头,至少有6个字符,第六个字符不能是空的或0,而且总共不能超过72个字符(=1+4+1+66)。
Fortran 66延续行=字符-“C”,4*字符,字符-(" " | “0”)。
66 * [字符] 。
*
—————————————————————————————————
As examples the following syntax-rules illustrate the facilities for expressing repetition.

aa = “A”;
bb=3* aa, “B”; cc=3* [aa], “C”;
dd = {aa}, “D”;
ee = aa, {aa}, “E”;
ff=3* aa,3* [aa], “F”;
gg=3* {aa}, “D”;

Terminal-strings defined by these rules are as follows:

aa: A bb: AAAB
cc: C AC AAC AAAC
dd: D AD AAD AAAD AAAAD etc.
ee: AE AAE AAAE AAAAE AAAAAE etc. ff: AAAF AAAAF AAAAAF AAAAAAF

NOTE — The definition for gg, although syntactically valid, is not sensible. The sequences of symbols represented by gg are identical with those given by dd but cannot be parsed unambiguously.
这部分比较容易,不翻译了。
—————————————————————————————————
As examples the following syntax-rules illustrate the facilities provided by the except-symbol.

letter = “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”;
vowel = “A” | “E” | “I” | “O” | “U”; consonant = letter - vowel;
ee = {“A”}-, “E”;

Terminal-strings defined by these rules are as follows:

letter: A B C D E F G H I J etc. vowel: A E I O U
consonant: B C D F G H J K L M etc. ee: AE AAE AAAE AAAAE AAAAAE etc.

NOTE — “A” - represents a sequence of one or more A’s because it is a syntactic-term with an empty syntactic-exception.

————————————————————————————————

EBNF实例讲解(翻译自Extended BNF. ISO/IEC 14977 : 1996(E))_第1张图片

串联符号 ,
定义符号 =
定义分隔符(我理解类似于或) 竖线
结束评论符 *)
结束元组符号 )
结束选择符号 ]
结束重复符号 }
集合差集符号 -
引用符号 ·
重复符号 *
不理解
不理解
开始评论符号 (*
开始元组符号 (
开始选择符号 [
开始重复符号 {
终结符号 ;

EBNF实例讲解(翻译自Extended BNF. ISO/IEC 14977 : 1996(E))_第2张图片
附上维基百科及翻译
可以省略或重复的表达式可以用大括号{…}表示:

自然数= 不包括零的数字, { digit } ;
在这种情况下,串1,2,…,10,…,10000,…都是正确的表达式。为了表示这一点,花括号中设置的所有内容都可以任意重复,包括根本不重复。

可以通过方括号[…]表示选项。也就是说,方括号内设置的所有内容可能只出现一次,或者根本不出现:

整数= “ 0” | [ “-” ], 自然数;
因此,整数是零(0)或自然数,其后可以是可选的减号。

EBNF还提供(除其他外)语法,用于描述(指定次数)重复,排除生成的某些部分以及在EBNF语法中插入注释。EBNF实例讲解(翻译自Extended BNF. ISO/IEC 14977 : 1996(E))_第3张图片
EBNF实例讲解(翻译自Extended BNF. ISO/IEC 14977 : 1996(E))_第4张图片
维基百科的其它例子(都是字面含义很容易懂):
digit excluding zero = “1” | “2” | “3” | “4” | “5” | “6” | “7” | “8” | “9” ;
digit = “0” | digit excluding zero ;

twelve = “1”, “2” ;
two hundred one = “2”, “0”, “1” ;
three hundred twelve = “3”, twelve ;
twelve thousand two hundred one = twelve, two hundred one ;

letter = “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” | “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” ;
digit = “0” | “1” | “2” | “3” | “4” | “5” | “6” | “7” | “8” | “9” ;
symbol = “[” | “]” | “{” | “}” | “(” | “)” | “<” | “>”
| “’” | ‘"’ | “=” | “|” | “.” | “,” | “;” ;
character = letter | digit | symbol | “_” ;

identifier = letter , { letter | digit | “_” } ;
terminal = “’” , character , { character } , “’”
| ‘"’ , character , { character } , ‘"’ ;

lhs = identifier ;
rhs = identifier
| terminal
| “[” , rhs , “]”
| “{” , rhs , “}”
| “(” , rhs , “)”
| rhs , “|” , rhs
| rhs , “,” , rhs ;

rule = lhs , “=” , rhs , “;” ;
grammar = { rule } ;

你可能感兴趣的:(bnf范式,ebnf)