巴克斯範式

來源:互聯網
上載者:User

BNF是為了描述ALGOL 60語言而出現的。

 

 

http://www.blog.edu.cn/user1/18646/archives/2005/139037.shtml

巴科斯範式及其擴充

BNF & Augmented BNF   
     
     什麼是巴科斯範式?
  
  巴科斯範式(BNF: Backus-Naur Form 的縮寫)是由 John Backus 和 Peter Naur 首先引入的用來描述電腦語言文法的符號集。
  現在,幾乎每一位新程式設計語言書籍的作者都使用巴科斯範式來定義程式設計語言的文法規則。   
     
     巴科斯範式的內容  

在雙引號中的字("word")代表著這些字元本身。而double_quote用來代表雙引號。
在雙引號外的字(有可能有底線)代表著文法部分。
角括弧( < > )內包含的為必選項。
方括弧( [ ] )內包含的為可選項。
大括弧( { } )內包含的為可重複0至無數次的項。
豎線( | )表示在其左右兩邊任選一項,相當於"OR"的意思。
::= 是“被定義為”的意思。 
   
     巴科斯範式樣本  

         這是用BNF來定義的Java語言中的For語句的執行個體:

FOR_STATEMENT ::=
      "for" "(" ( variable_declaration |
  ( expression ";" ) | ";" )
      [ expression ] ";"
      [ expression ] ";"
      ")" statement

         這是Oracle packages的BNF定義:

package_body ::= "package" package_name "is"
package_obj_body { 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 { 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 }
rule       ::=  identifier  "::="  expression
expression ::=  term { "|" term }
term       ::=  factor { factor }
factor     ::=  identifier |
                quoted_symbol |
                "("  expression  ")" |
                "["  expression  "]" |
                "{"  expression  "}"
identifier ::=  letter { letter | digit }
quoted_symbol ::= """ { any_character } """

     
     擴充的巴科斯範式 Augmented BNF 
 
  RFC2234 定義了擴充的巴科斯範式(ABNF)。近年來在Internet的定義中ABNF被廣泛使用。ABNF做了更多的改進,比如說,在ABNF中,角括弧不再需要。 
rfc2234:
http://www.rfc-editor.org/cgi-bin/rfcdoctype.pl?loc=RFC&letsgo=2234&type=ftp&file_format=txt

更多資源:
http://www-128.ibm.com/developerworks/cn/java/j-diag/part19/index.html

  • W3C 就有關 使用 BNF 符號提供了八種符號約定。

  • 可以在這裡找到關於 BNF 符號的簡史和介紹。

  • 有關 BNF 的更多資訊,請參閱這個 擴充 BNF 符號的列表。

 

What is BNF notation?

http://cui.unige.ch/db-research/Enseignement/analyseinfo/AboutBNF.html#Marcotty86
(包括BNF的曆史和較早的文獻)

 

answers.com上的介紹:

http://www.answers.com/topic/backus-naur-form-3

有很多有意義的文獻:

  • Algol-60 BNF, the original BNF.

  • Sample grammars at the BNF Web club.

  • [1] contains a posting on news:comp.compilers that explains some of the history of the two names (Backus-Naur form vs. Backus normal form).

  • Article BNF and EBNF: What are they and how do they work? by Lars Marius Garshol.

  • RFC 4234 Augmented BNF for Syntax Specifications: ABNF

  • Comparision of different variants of BNF

  • Syntax diagram of EBNF

  • Generation of syntax diagrams from EBNF

 

 

One syntax for specifying BNF grammars can be found in RFC 2234. Another can be found in the ISO 14977 standard.

 

 

相當簡潔,全面的BNF,EBNF定義(!!!!):

http://www-cgi.uni-regensburg.de/~brf09510/backus_naur_wirth.html

 

EBNF的國際標準ISO 14977

http://www.cl.cam.ac.uk/~mgk25/iso-14977.pdf

 

 

BNF多個版本的比較

http://www-cgi.uni-regensburg.de/~brf09510/grammartypes.html

 

Augmented BNF for Syntax Specifications: ABNF

ftp://ftp.rfc-editor.org/in-notes/rfc4234.txt

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.