發展歷史
約翰·巴科斯首次在ALGOL 58中實現巴科斯範式。
彼得·諾爾在ALGOL 60之中,進一步發展它的概念並將它的符號加以簡化,稱其為巴科斯範式(Backus Normal Form)。但
高德納主張應稱為巴科斯-諾爾範式(Backus–Naur Form),因為它不算是一種正規形式(Normal form)。
內容
在雙引號中的字("word")代表著這些字元本身。而double_quote用來代表雙引號。
在雙引號外的字(有可能有下劃線)代表著語法部分。
尖括弧( < > )內包含的為必選項。
方括弧( [ ] )內包含的為可選項。
大括弧( { } )內包含的為可重複0至無數次的項。
豎線( | )表示在其左右兩邊任選一項,相當於"OR"的意思。
::= 是“被定義為”的意思。
巴科斯範式示例
FOR_STATEMENT ::=
"for" "(" ( variable_declaration |
( expression ";" ) | ";" )
[ expression ] ";"
[ expression ]
")" statement
這是Oracle packages的BNF定義:
package_body ::= "package" package_name "is"
package_obj_body
[ "begin" seq_of_statements ]
"end" [ package_name ] ";"
package_obj_body ::= variable_declaration
| subtype_declaration
| cursor_declaration
| cursor_body
| exception_declaration
| record_declaration
| plsql_table_declaration
| procedure_body
| function_body
procedure_body ::= "procedure" procedure_name
[ "(" argument { "," argument } ")" ]
"return" return_type
"is"
[ "declare" declare_spec ";" { declare_spec ";" } ]
"begin"
seq_of_statements
[ "exception" exception_handler ]
"end" [ procedure_name ] ";"
statement ::= comment
| assignment_statement
| exit_statement
| goto_statement
| if_statement
| loop_statement
| null_statement
| raise_statement
| return_statement
| sql_statement
| plsql_block
這是用BNF來定義的BNF本身的例子:
syntax ::=
rule ::= identifier "::=" expression
expression ::= term { "|" term }
term ::= factor
factor ::= identifier |
quoted_symbol |
"(" expression ")" |
"[" expression "]" |
"{" expression "}"
identifier ::= letter { letter | digit }
quoted_symbol ::= """ """
擴展的內容
RFC2234 定義了擴展的巴科斯範式(ABNF)。近年來在Internet的定義中ABNF被廣泛使用。ABNF做了更多的改進,比如說,在ABNF中,尖括弧不再需要。