产生规则格式如下:
symbol ::= expression
::=
左边的语法符号称为规则的左手边(LHS, left-hand side)。
::=
右边的语法符号称为规则的右手边(RHS, right-hand side)。
ENBF 是对 BNF 的扩展,EBNF 有很多变种, W3C EBNF 是其中一种。
W3C EBNF 是 BNF 的一种扩展,下面使用 W3C EBNF 描述了 W3C EBNF 的语法。
W3C EBNF Syntax
Grammar ::= Production*
Production
::= NCName '::=' ( Choice | Link )
NCName ::= [http://www.w3.org/TR/xml-names/#NT-NCName]
Choice ::= SequenceOrDifference ( '|' SequenceOrDifference )*
SequenceOrDifference
::= (Item ( '-' Item | Item* ))?
Item ::= Primary ( '?' | '*' | '+' )*
Primary ::= NCName | StringLiteral | CharCode | CharClass | '(' Choice ')'
StringLiteral
::= '"' [^"]* '"' | "'" [^']* "'"
CharCode ::= '#x' [0-9a-fA-F]+
CharClass
::= '[' '^'? ( Char | CharCode | CharRange | CharCodeRange )+ ']'
Char ::= [http://www.w3.org/TR/xml#NT-Char]
CharRange
::= Char '-' ( Char - ']' )
CharCodeRange
::= CharCode '-' CharCode
Link ::= '[' URL ']'
URL ::= [^#x5D:/?#]+ '://' [^#x5D#]+ ('#' NCName)?
Whitespace
::= S | Comment
S ::= #x9 | #xA | #xD | #x20
Comment ::= '/*' ( [^*] | '*'+ [^*/] )* '*'* '*/'
算术表达式语法
expression ::= term | term "+" expression
term ::= factor | factor "*" term
factor ::= constant | variable | "(" expression ")"
variable ::= "x" | "y" | "z"
constant ::= digit | digit constant
digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"