跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
最近更改
随机页面
MediaWiki帮助
GSXAB的知识库
搜索
搜索
外观
登录
个人工具
登录
Advertising:
查看“︁扩展 Backus–Naur 范式”︁的源代码
页面
讨论
简体中文
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
刷新
常规
链入页面
相关更改
特殊页面
页面信息
外观
移至侧栏
隐藏
←
扩展 Backus–Naur 范式
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
[[分类:形式语言]] [[分类:形式语言实例]] [[分类:语法分析]] {{InfoBox |name=扩展巴科斯–诺尔范式 |eng_name=extended Backus–Naur form |aliases=EBNF,扩展巴克斯–瑙尔范式,扩展BNF,extended BNF }} '''扩展<ins>巴科斯</ins>–<ins>诺尔</ins>范式'''('''extended Backus–Naur form''')或'''扩展 BNF''' ,缩写为 '''EBNF''' ,指为[[上下文无关文法]]设计的形式元语言语法 [[BNF]] 的扩展。 EBNF 简化了一些常用语法的表示。 由于 EBNF ,去除了繁杂的尖括号并补充了一些常用表示,比起 BNF 更加好读。 因此 EBNF 在教学和语法说明中广泛存在,使用场合往往是向人类说明而非严格定义,因此形式不完全固定且往往混入更多方便的符号,导致其存在着很多非正式的变体。 这些过多的细微变体导致了一定混乱,且最后也没有出现成功统一的标准。 一个比较常见的变体是 ISO/IEC 14977 ,本文也以此为准。 == 形式语言定义 == 定义形式语言的字母表和规则如下: === 字母表 === BNF 的字母表是以下集合的并集: * 文法符号(终结符和非终结符的统称)集合 ** 终结符的集合 <math>V_N</math> ,其中任意元素都是字面量。字面量形式上使用双引号包围,如 <syntaxhighlight inline lang="ebnf">"abc"</syntaxhighlight> 等;特别地,允许出现空串 <syntaxhighlight inline lang="ebnf">""</syntaxhighlight> ,当需要双引号字符时可以使用单引号包围以免产生混淆 <syntaxhighlight inline lang="ebnf">'"'</syntaxhighlight> ; ** 非终结符的集合 <math>V_T</math> 。非终结符是正常的短语,可以包含空格,如 <syntaxhighlight inline lang="ebnf">digit</syntaxhighlight> 或 <syntaxhighlight inline lang="ebnf">digit excluding zero</syntaxhighlight> ; * 辅助符号的集合,包括: ** 推导符号 <syntaxhighlight inline lang="ebnf">=</syntaxhighlight> ; ** 连接符号 <syntaxhighlight inline lang="ebnf">,</syntaxhighlight> ; ** 规则结束分隔符 <syntaxhighlight inline lang="ebnf">;</syntaxhighlight> ; ** 选择符号 <syntaxhighlight inline lang="ebnf">|</syntaxhighlight> ; ** 可选符号 <syntaxhighlight inline lang="ebnf">[</syntaxhighlight> 和 <syntaxhighlight inline lang="ebnf">]</syntaxhighlight> ,或 <syntaxhighlight inline lang="ebnf">(/</syntaxhighlight> 和 <syntaxhighlight inline lang="ebnf">/)</syntaxhighlight> ; ** 重复符号 <syntaxhighlight inline lang="ebnf">{</syntaxhighlight> 和 <syntaxhighlight inline lang="ebnf">}</syntaxhighlight> ,或 <syntaxhighlight inline lang="ebnf">(:</syntaxhighlight> 和 <syntaxhighlight inline lang="ebnf">:)</syntaxhighlight> ; ** 分组符号 <syntaxhighlight inline lang="ebnf">(</syntaxhighlight> 和 <syntaxhighlight inline lang="ebnf">)</syntaxhighlight> ; ** 注释 <syntaxhighlight inline lang="ebnf">(*</syntaxhighlight> 和 <syntaxhighlight inline lang="ebnf">*)</syntaxhighlight> ** 特殊序列 <syntaxhighlight inline lang="ebnf">?</syntaxhighlight> ; ** 排除 <syntaxhighlight inline lang="ebnf">-</syntaxhighlight> 。 === 规则 === ==== BNF 定义 ==== <syntaxhighlight lang="bnf"> <syntax> ::= <rule> | <rule> <syntax> <rule> ::= <whitespace> <rule-name> <whitespace> "=" <whitespace> <rhs> <line-end> <opt-whitespace> ::= <whitespace> <opt-whitespace> | "" <line-end> ::= ";" | "." <rhs> ::= <alternation> <alternation> ::= <alternation> | <alternation> <opt-whitespace> "|" <opt-whitespace> <concatenation> <concatenation> ::= <concatenation> | <concatenation> <opt-whitespace> "," <opt-whitespace> <factor> <factor> ::= <term> | <term> <opt-whitespace> "-" <opt-whitespace> <term> <term> ::= <literal> | <special> | <rule-name> | "(" <opt-whitespace> <rhs> <opt-whitespace> ")" | "[" <opt-whitespace> <rhs> <opt-whitespace> "]" | "{" <opt-whitespace> <rhs> <opt-whitespace> "}" <literal> ::= '"' <text1> '"' | "'" <text2> "'" <text1> ::= "" | <character1> <text1> <text2> ::= "" | <character2> <text2> <special> ::= "?" <opt-whitespace> <special-text> <opt-whitespace> "?" <special-text> ::= <character> <special-text> <character> ::= <letter> | <digit> | <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" | "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> ::= "|" | " " | "!" | "#" | "$" | "%" | "&" | "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | ":" | ";" | ">" | "=" | "<" | "?" | "@" | "[" | "\" | "]" | "^" | "_" | "`" | "{" | "}" | "~" <whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\b" <character1> ::= <character> | "'" <character2> ::= <character> | '"' <rule-name> ::= <letter> | <rule-name> <rule-char> <rule-char> ::= <letter> | <digit> | "_" </syntaxhighlight> ==== 常见变体 ==== 很多变体中使用后缀 <code>?,*,+</code> 来指定重复次数。 有些变体不允许符号存在空格,而用空格代替逗号表示连接运算。
返回
扩展 Backus–Naur 范式
。
Advertising: