BNF is an acronym for "Backus Naur Form". John Backus and
Peter Naur introduced for the first time a formal notation
to describe the syntax of a given language (This was for the description
of the ALGOL 60
programming language, see [Naur 60]).
To be precise, most of BNF was introduced by Backus in a report presented at
an earlier UNESCO conference on ALGOL 58. Few read the report, but when
Peter Naur read it he was surprised at some of the differences he found
between his and Backus's interpretation of ALGOL 58. He decided that for the
successor to ALGOL, all participants of the first design had come to
recognize some weaknesses, should be given in a similar form so that all
participants should be aware of what they were agreeing to. He made a
few modificiations that are almost universally used and drew up on his
own the BNF for ALGOL 60 at the meeting where it was designed. Depending
on how you attribute presenting it to the world, it was either by Backus
in 59 or Naur in 60. (For more details on this period of
programming languages history, see the
introduction to Backus's Turing award article in Communications of the
ACM, Vol. 21, No. 8, august 1978. This note was suggested by
William B. Clodius
from Los Alamos Natl. Lab).
Since then, almost every author of books on new programming languages
used it to specify the syntax rules of the language. See [Jensen 74] and [Wirth 82] for examples.
The following is taken from [Marcotty 86]:
--------------------------------------------------------------------------------
The meta-symbols of BNF are:
::=meaning "is defined as"
| meaning "or"
< >angle brackets used to surround category names.
The angle brackets distinguish syntax rules names (also called
non-terminal symbols) from terminal symbols which are written exactly
as they are to be represented. A BNF rule defining a nonterminal has the form:
nonterminal ::= sequence_of_alternatives consisting of strings of
terminals or nonterminals separated by the meta-symbol |
For example, the BNF production for a mini-language is:
::= program
begin
end ;
This shows that a mini-language program consists of the keyword "program"
followed by the declaration sequence, then the keyword "begin" and the
statements sequence, finally the keyword "end" and a semicolon.
(end of quotation)--------------------------------------------------------------------------------
In fact, many authors have introduced some slight extensions of BNF for the
ease of use:
optional items are enclosed in meta symbols [ and ], example:
::= if then
[ else
]
end if ;
repetitive items (zero or more times) are enclosed in meta
symbols { and }, example:
::= { | }
this rule is equivalent to the recursive rule:
::= |
[ | ]
terminals of only one character are surrounded by quotes (") to
distinguish them from meta-symbols, example:
::= { ";" }
in recent text books, terminal and non-terminal symbols are distingued
by using bold faces for terminals and suppressing < and > around
non-terminals. This improves greatly the readability. The example then becomes:
if_statement ::= if boolean_expression then
statement_sequence
[ else
statement_sequence ]
end if ";"
Now as a last example (maybe not the easiest to read !), here is the
definition of BNF expressed in 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 } """
BNF is not ony important to describe syntax rules in books, but it is
very commonly used (with variants) by syntactic tools. See for example
any book on LEX and YACC,
the standard UNIX parser generators. If you
have access to any Unix machine, you will probably find a chapter of
the documentation on these tools.
--------------------------------------------------------------------------------
Some references:
[Naur 60]
NAUR, Peter (ed.), "Revised Report on the Algorithmic
Language ALGOL 60.", Communications of the ACM, Vol. 3 No.5, pp.
299-314, May 1960.
[Jensen 74]
JENSEN, Kathleen, WIRTH, Niklaus,
"PASCAL user manual and report",
Lecture notes in computer science ; vol. 18.,
Berlin [etc.] : Springer, 1974., 1974.
[Johnson 75]
S.C. Johnson,
"Yacc: Yet Another Compiler Compiler",
Computer Science Technical Report #32,
Bell Laboratories,
Murray Hill, NJ, 1975.
[Wirth 82]
WIRTH, Niklaus.,
Programming in Modula-2,
Berlin, Heidelberg: Springer, 1982.
[Marcotty 86]
M. Marcotty & H. Ledgard,
The World of Programming Languages,
Springer-Verlag,
Berlin 1986., pages 41 and following.
分享到:
相关推荐
c++ bnf i need c++ bnf i need c++ bnf i need]
BNF详细的语法定义 BNF详细的语法定义 BNF详细的语法定义
BNF Notation ..... xxxvi ANSI/ISO Compliance ... xxxvi Requirements ..... xxxvi Does the Oracle Pro*C/C Precompiler Meet Industry Standards?...... xxxvii Compliance...... xxxviii Certification .....
BNF语法开发指南,离线命令词语法构建的BNF语法开发指南
巴科斯范式(BNF)查看器,可查看BNF范式生成的First集,Follow集,Select集和预测分析表,是学习编译原理的好工具。 附带标准c的bnf范式文件。
java syntax represented by bnf
RRDiagram, 从代码或者BNF生成铁路图,从代码生成 BNF RRDiagram从代码或者BNF生成铁路图。 从代码生成 BNF 。rtc图是一个Java库,它从代码中生成铁路图( 也称为语法图),从。 输出格式是一个非常 compact SVG图像,...
C语言(子集)的BNF文法描述,自己感觉还是挺全的,基本上把C语言中该有部分都包含在内了,,,下了绝对不会后悔的。。。。
「编程语言」课程的配套资源,包含了C、Java和Python的BNF范式生成规则。
sql各年标准bnf语法之xml展示,利用了xml的扩展特性,对BNF语法进行了元素显示深度扩展,十分利于查看sql语法,是学习sql和开发数据库软件的好帮手。 文件也包含了sql2011标准文档,下载来源是此网站。内包含一个程序...
C语言BNF语法的图形化展示,收集自互联网,是深入研究C语言语法或者编译原理以及C语言编译器的好材料。
一个bnf语法示例,用于离线识别命令,通过slot 组合, 可以使用
sql-92_bnf巴格达范式 for antler
C语言(子集)的BNF文法描述,自己感觉还是挺全的,基本上把C语言中该有部分都包含在内了,,,下了绝对不会后悔的。。。。
sql 92的 bnf范式,学习sql 92标准的最权威参考
用BNF描述一个小的语言,并实现其语法分析器(含词法分析部分)。
sql 99的 bnf范式,学习sql 99标准的最权威参考。
bnf 一个用于解析Backus–Naur形式的无上下文语法的库。可解析的BNF语法是什么样的? 以下的语法,举例说明了兼容的语法。 (*注:解析器允许使用可选的“;”来指示生产的结束) <postal> ::= <name> <street> <zip>...
大家可以去 http://c.comsci.us/syntax/ 下载 哪里还有更多的资料 对于一个自己实现编译器,或学习yacc lex,antlr非常有用
这个语法分析器用到的是自顶向下的递归调用的方法,根据Cminus语言的文法规则 的BNF范式编写递归调用的代码,parse方法是程序的入口,它调用的stmt_sequence完成整个语法分析工作,stmt_sequence背后是12个互相调用...