BNFs describe how to combine different symbols to produce a syntactically correct sequence. BNFs consist of three components: a set of non-terminal symbols, a set of terminal symbols, and rules for replacing non-terminal symbols with a sequence of symbols.[1] These so-called "derivation rules" are written as
<symbol>::= __expression__
where:
<symbol>[2] is a nonterminal variable that is always enclosed between the pair <>.
::= means that the symbol on the left must be replaced with the expression on the right.
__expression__ consists of one or more sequences of either terminal or nonterminal symbols where each sequence is separated by a vertical bar "|" indicating a choice, the whole being a possible substitution for the symbol on the left.
All syntactically correct sequences must be generated in the following manner:
Initialize the sequence so that it just contains one start symbol.
Apply derivation rules to this start symbol and the ensuing sequences of symbols.[1]
Applying rules in this manner can produce longer and longer sequences, so many BNF definitions allow for a special "delete" symbol to be included in the specification. We can specify a rule that allows us to replace some symbols with this "delete" symbol, which is meant to indicate that we can remove the symbols from our sequence and still have a syntactically correct sequence.[1]
Example
As an example, consider this possible BNF for a U.S. postal address:
A postal address consists of a name-part, followed by a street-address part, followed by a zip-code part.
A name-part consists of either: a personal-part followed by a last name followed by an optional suffix (Jr. Sr., or dynastic number) and end-of-line, or a personal part followed by a name part (this rule illustrates the use of recursion in BNFs, covering the case of people who use multiple first and middle names and initials).[3]
A personal-part consists of either a first name or an initial followed by a dot.
A street address consists of a house number, followed by a street name, followed by an optional apartment specifier, followed by an end-of-line.
A zip-part consists of a town-name, followed by a comma, followed by a state code, followed by a ZIP-code followed by an end-of-line.
An opt-suffix-part consists of a suffix, such as "Sr.", "Jr." or a roman-numeral, or an empty string (i.e. nothing).
An opt-apt-num consists of a prefix "Apt" followed by an apartment number, or an empty string (i.e. nothing).
Note that many things (such as the format of a first-name, apartment number, ZIP-code, and Roman numeral) are left unspecified here. If necessary, they may be described using additional BNF rules.
History
The idea of describing the structure of language using rewriting rules can be traced back to at least the work of Pāṇini, an ancient Indian Sanskrit grammarian and a revered scholar in Hinduism who lived sometime between the 6th and 4th century BC.[4][5] His notation to describe Sanskrit word structure is equivalent in power to that of Backus and has many similar properties.
In Western society, grammar was long regarded as a subject for teaching, rather than scientific study; descriptions were informal and targeted at practical usage. In the first half of the 20th century, linguists such as Leonard Bloomfield and Zellig Harris started attempts to formalize the description of language, including phrase structure.
John Backus, a programming language designer at IBM, proposed a metalanguage of "metalinguistic formulas"[2][9][10]
to describe the syntax of the new programming language IAL, known today as ALGOL 58 (1959). His notation was first used in the ALGOL 60 report.
BNF is a notation for Chomsky's context-free grammars. Backus was familiar with Chomsky's work.[11]
As proposed by Backus, the formula defined "classes" whose names are enclosed in angle brackets. For example, <ab>. Each of these names denotes a class of basic symbols.[2]
Further development of ALGOL led to ALGOL 60. In the committee's 1963 report, Peter Naur called Backus's notation Backus normal form. Donald Knuth argued that BNF should rather be read as Backus–Naur form, as it is "not a normal form in the conventional sense",[12]
unlike, for instance, Chomsky normal form. The name Pāṇini Backus form was also once suggested in view of the fact that the expansion Backus normal form may not be accurate, and that Pāṇini had independently developed a similar notation earlier.[13]
BNF is described by Peter Naur in the ALGOL 60 report as metalinguistic formula:[14]
Sequences of characters enclosed in the brackets <> represent metalinguistic variables whose values are sequences of symbols. The marks "::=" and "|" (the latter with the meaning of "or") are metalinguistic connectives. Any mark in a formula, which is not a variable or a connective, denotes itself. Juxtaposition of marks or variables in a formula signifies juxtaposition of the sequence denoted.
Another example from the ALGOL 60 report illustrates a major difference between the BNF metalanguage and a Chomsky context-free grammar. Metalinguistic variables do not require a rule defining their formation. Their formation may simply be described in natural language within the <> brackets. The following ALGOL 60 report section 2.3 comments specification, exemplifies how this works:
For the purpose of including text among the symbols of a program the following "comment" conventions hold:
The sequence of basic symbols:
is equivalent to
;comment <any sequence not containing ';'>;
;
begincomment <any sequence not containing ';'>;
begin
end <any sequence not containing 'end' or ';' or 'else'>
end
Equivalence here means that any of the three structures shown in the left column may be replaced, in any occurrence outside of strings, by the symbol shown in the same line in the right column without any effect on the action of the program.
Naur changed two of Backus's symbols to commonly available characters. The ::= symbol was originally a :≡. The | symbol was originally the word "or" (with a bar over it).[9]: 14
BNF is very similar to canonical-formBoolean algebra equations that are, and were at the time, used in logic-circuit design. Backus was a mathematician and the designer of the FORTRAN programming language. Studies of Boolean algebra is commonly part of a mathematics curriculum. Neither Backus nor Naur described the names enclosed in < > as non-terminals. Chomsky's terminology was not originally used in describing BNF. Naur later described them as classes in ALGOL course materials.[2] In the ALGOL 60 report they were called metalinguistic variables. Anything other than the metasymbols ::=, |, and class names enclosed in < > are symbols of the language being defined. The metasymbol ::= is to be interpreted as "is defined as". The | is used to separate alternative definitions and is interpreted as "or". The metasymbols < > are delimiters enclosing a class name. BNF is described as a metalanguage for talking about ALGOL by Peter Naur and Saul Rosen.[2]
In 1947 Saul Rosen became involved in the activities of the fledgling Association for Computing Machinery, first on the languages committee that became the IAL group and eventually led to ALGOL. He was the first managing editor of the Communications of the ACM.[clarification needed] BNF was first used as a metalanguage to talk about the ALGOL language in the ALGOL 60 report. That is how it is explained in ALGOL programming course material developed by Peter Naur in 1962.[2] Early ALGOL manuals by IBM, Honeywell, Burroughs and Digital Equipment Corporation followed the ALGOL 60 report using it as a metalanguage. Saul Rosen in his book[15] describes BNF as a metalanguage for talking about ALGOL. An example of its use as a metalanguage would be in defining an arithmetic expression:
<expr>::=<term>|<expr><addop><term>
The first symbol of an alternative may be the class being defined, the repetition, as explained by Naur, having the function of specifying that the alternative sequence can recursively begin with a previous alternative and can be repeated any number of times.[2] For example, above <expr> is defined as a <term> followed by any number of <addop> <term>.
In some later metalanguages, such as Schorre's META II, the BNF recursive repeat construct is replaced by a sequence operator and target language symbols defined using quoted strings. The < and > brackets were removed. Parentheses () for mathematical grouping were added. The <expr> rule would appear in META II as
These changes enabled META II and its derivative programming languages to define and extend their own metalanguage, at the cost of the ability to use a natural language description, metalinguistic variable, language construct description. Many spin-off metalanguages were inspired by BNF.[citation needed] See META II, TREE-META, and Metacompiler.
A BNF class describes a language construct formation, with formation defined as a pattern or the action of forming the pattern. The class name expr is described in a natural language as a <term> followed by a sequence <addop> <term>. A class is an abstraction; we can talk about it independent of its formation. We can talk about term, independent of its definition, as being added or subtracted in expr. We can talk about a term being a specific data type and how an expr is to be evaluated having specific combinations of data types, or even reordering an expression to group data types and evaluation results of mixed types. The natural-language supplement provided specific details of the language class semantics to be used by a compiler implementation and a programmer writing an ALGOL program. Natural-language description further supplemented the syntax as well. The integer rule is a good example of natural and metalanguage used to describe syntax:
<integer>::=<digit>|<integer><digit>
There are no specifics on white space in the above. As far as the rule states, we could have space between the digits. In the natural language we complement the BNF metalanguage by explaining that the digit sequence can have no white space between the digits. English is only one of the possible natural languages. Translations of the ALGOL reports were available in many natural languages.
The origin of BNF is not as important as its impact on programming language development.[citation needed] During the period immediately following the publication of the ALGOL 60 report BNF was the basis of many compiler-compiler systems.
Some, like "A Syntax Directed Compiler for ALGOL 60" developed by Edgar T. Irons and "A Compiler Building System" Developed by Brooker and Morris, directly used BNF. Others, like the Schorre Metacompilers, made it into a programming language with only a few changes. <class name> became symbol identifiers, dropping the enclosing <, > and using quoted strings for symbols of the target language. Arithmetic-like grouping provided a simplification that removed using classes where grouping was its only value. The META II arithmetic expression rule shows grouping use. Output expressions placed in a META II rule are used to output code and labels in an assembly language. Rules in META II are equivalent to a class definitions in BNF. The Unix utility yacc is based on BNF with code production similar to META II. yacc is most commonly used as a parser generator, and its roots are obviously BNF.
BNF today is one of the oldest computer-related languages still in use.[citation needed]
Further examples
BNF's syntax itself may be represented with a BNF like the following:
The original BNF did not use quotes as shown in <literal> rule. This assumes that no whitespace is necessary for proper interpretation of the rule.
<EOL> represents the appropriate line-end specifier (in ASCII, carriage-return, line-feed or both depending on the operating system). <rule-name> and <text> are to be substituted with a declared rule's name/label or literal text, respectively.
In the U.S. postal address example above, the entire block-quote is a <syntax>. Each line or unbroken grouping of lines is a rule; for example one rule begins with <name-part> ::=. The other part of that rule (aside from a line-end) is an expression, which consists of two lists separated by a vertical bar |. These two lists consists of some terms (three terms and two terms, respectively). Each term in this particular rule is a rule-name.
There are many variants and extensions of BNF, generally either for the sake of simplicity and succinctness, or to adapt it to a specific application. One common feature of many variants is the use of regular expression repetition operators such as * and +. The extended Backus–Naur form (EBNF) is a common one.
Another common extension is the use of square brackets around optional items. Although not present in the original ALGOL 60 report (instead introduced a few years later in IBM's PL/I definition), the notation is now universally recognised.
Many BNF specifications found online today are intended to be human-readable and are non-formal. These often include many of the following syntax rules and extensions:
Optional items enclosed in square brackets: [<item-x>].
Items existing 0 or more times are enclosed in curly brackets or suffixed with an asterisk (*) such as <word> ::= <letter> {<letter>} or <word> ::= <letter> <letter>* respectively.
Items existing 1 or more times are suffixed with an addition (plus) symbol, +, such as <word> ::= <letter>+.
Terminals may appear in bold rather than italics, and non-terminals in plain text rather than angle brackets.
Where items are grouped, they are enclosed in simple parentheses.
Software using BNF or variants
Software that accepts BNF (or a superset) as input
RPA BNF parser.[17] Online (PHP) demo parsing: JavaScript, XML
XACT X4MR System,[18] a rule-based expert system for programming language translation
XPL Analyzer, a tool which accepts simplified BNF for a language and produces a parser for that language in XPL; it may be integrated into the supplied SKELETON program, with which the language may be debugged[19] (a SHARE contributed program, which was preceded by A Compiler Generator[20])
bnfparser2,[21] a universal syntax verification utility
bnf2xml,[22] Markup input with XML tags using advanced BNF matching
Yacc, parser generator (most commonly used with the Lex preprocessor)
Racket's parser tools, lex and yacc-style parsing (Beautiful Racket edition)
Qlik Sense, a BI tool, uses a variant of BNF for scripting [24]
BNF Converter (BNFC[25]), operating on a variant called "labeled Backus–Naur form" (LBNF). In this variant, each production for a given non-terminal is given a label, which can be used as a constructor of an algebraic data type representing that nonterminal. The converter is capable of producing types and parsers for abstract syntax in several languages, including Haskell and Java
^ abcdefgThe meaning of syntactic formula may be further explained by saying that words enclosed in the brackets < >, like <ab>, denote classes whose members are sequences of basic symbols. Class designations of this kind are found in any description of a language. For describing ordinary natural languages designation like word, verb, noun, are used. .[8]: 5, Note 1
^"Panini biography". School of Mathematics and Statistics, University of St Andrews, Scotland. Retrieved 2014-03-22.
^Ingerman, Peter Zilahy (March 1967). ""Pāṇini-Backus Form" Suggested". Communications of the ACM. 10 (3). Association for Computing Machinery: 137. doi:10.1145/363162.363165. S2CID52817672. Ingerman suggests that the Backus Normal Form be renamed to the Pāṇini-Backus Form, to give due credit to Pāṇini as the earliest independent inventor.
^If the target processor is System/360, or related, even up to z/System, and the target language is similar to PL/I (or, indeed, XPL), then the required code "emitters" may be adapted from XPL's "emitters" for System/360.
RFC5234 — Augmented BNF for Syntax Specifications: ABNF.
RFC5511 — Routing BNF: A Syntax Used in Various Protocol Specifications.
ISO/IEC 14977:1996(E) Information technology – Syntactic metalanguage – Extended BNF, available from "Publicly available", Standards, ISO or from Kuhn, Marcus, Iso 14977(PDF), UK: CAM (the latter is missing the cover page, but is otherwise much cleaner)
Language grammars
Bernhard, Algol-60 BNF, DE: LRZ München, the original BNF.
"BNF grammars for SQL-92, SQL-99 and SQL-2003", Savage, AU: Net, freely available BNF grammars for SQL.
"BNF Web Club", DB research, CH: Unige, archived from the original on 2007-01-24, retrieved 2007-01-25, freely available BNF grammars for SQL, Ada, Java.
"Free Programming Language Grammars for Compiler Construction", Source code, The free country, freely available BNF/EBNF grammars for C/C++, Pascal, COBOL, Ada 95, PL/I.
American actor (born 2003) Jack Dylan GrazerGrazer at the 2019 WonderConBorn (2003-09-03) September 3, 2003 (age 20)Los Angeles, California, U.S.OccupationActorYears active2014–presentRelativesBrian Grazer (uncle) Jack Dylan Grazer (born September 3, 2003)[1][2][3] is an American actor. He[a] is known for his roles as Eddie Kaspbrak in the horror film It (2017) and its 2019 sequel, Freddy Freeman in the DC Extended Universe film Shazam! (2019) and i...
Austrian ice hockey player Ice hockey player Dominic Zwerger Zwerger with Austria in 2023Born (1996-07-16) July 16, 1996 (age 27)Dornbirn, AustriaHeight 6 ft 0 in (183 cm)Weight 205 lb (93 kg; 14 st 9 lb)Position Left wingShoots LeftNL team HC Ambrì-PiottaNational team AustriaNHL Draft UndraftedPlaying career 2017–present Dominic Zwerger (born July 16, 1996) is an Austrian professional ice hockey player. He is currently playing for the HC A...
Coordenadas: 45° 3' N 8° 43' E Suardi Comuna Localização SuardiLocalização de Suardi na Itália Coordenadas 45° 3' N 8° 43' E Região Lombardia Província Pavia Características geográficas Área total 9 km² População total 703 hab. Densidade 78,1 hab./km² Altitude 84 m Outros dados Comunas limítrofes Bassignana (AL), Frascarolo, Gambarana, Valenza (AL) Código ISTAT 018154 Código cadastral B014 Código postal 27030 P...
Anne, Princess Royal und Prinzessin von Oranien Prinzessin Anne, Princess Royal und Prinzessin von Oranien (* 2. November 1709 in Herrenhausen; † 12. Januar 1759 in Den Haag) war das zweite Kind und die älteste Tochter des britischen Königs und Braunschweiger Kurfürsten Georg II. aus dem Haus Hannover und seiner Frau Caroline von Ansbach. Sie war die Ehefrau des ersten Erbstatthalters der Niederlande, Wilhelms IV. Anne war die zweite Trägerin des Titels Princess Royal, der den ältesten T
Air Terjun Tanah MerahPanorama Air Terjun Tanah MerahLokasiKelurahan Tanah Merah, Kecamatan Samarinda Utara, Kota Samarinda, Kalimantan Timur, IndonesiaKoordinat0°26′00.6″S 117°14′02.4″E / 0.433500°S 117.234000°E / -0.433500; 117.234000Koordinat: 0°26′00.6″S 117°14′02.4″E / 0.433500°S 117.234000°E / -0.433500; 117.234000TipePlungeTinggi total15 meter (49 ft)Jumlah titik1 (Satu)Anak sungaiSungai Binanga Air terjun Tan...
У Вікіпедії є статті про інших людей із прізвищем Бондарчук. Роман Бондарчук Дата народження 14 січня 1982(1982-01-14)[1] (41 рік)Місце народження Херсон, Українська РСР, СРСРГромадянство УкраїнаПрофесія кінорежисер, сценарист, монтажерAlma mater Київський національний універ...
Untuk kegunaan lain, lihat Nihilisme. Artikel ini tidak memiliki referensi atau sumber tepercaya sehingga isinya tidak bisa dipastikan. Tolong bantu perbaiki artikel ini dengan menambahkan referensi yang layak. Tulisan tanpa sumber dapat dipertanyakan dan dihapus sewaktu-waktu.Cari sumber: Nihilisme metafisika – berita · surat kabar · buku · cendekiawan · JSTOR Nihilisme metafisika adalah teori filosofi ketiadaan semua benda, yaitu bahwa ada kemungkina...
Borough in Pennsylvania, United StatesDover, PennsylvaniaBoroughEnglehart Melchinger HouseLocation in York County and the U.S. state of Pennsylvania.DoverLocation of Dover in PennsylvaniaShow map of PennsylvaniaDoverDover (the United States)Show map of the United StatesCoordinates: 40°00′14″N 76°50′58″W / 40.00389°N 76.84944°W / 40.00389; -76.84944CountryUnited StatesStatePennsylvaniaCountyYorkSettled1764; 259 years ago (1764)Incorporated1...
Newspaper Reading EagleThe July 27, 2005, front page of the Reading EagleTypeDaily newspaperFormatBroadsheet (1867–2009; 2018–) Berliner (2009–2018)Owner(s)Reading Eagle CompanyPublisherMediaNews GroupFounded1867Headquarters345 Penn St.Reading, Pennsylvania 19603-0582, U.S.ISSN2469-3448Websitereadingeagle.com The Reading Eagle is the major daily newspaper in Reading, Pennsylvania. A family-owned newspaper until the spring of 2019, its reported circulation is 37,000 (daily) and 50,000 (S...
King of England from 1509 to 1547 For other uses, see Henry VIII (disambiguation). Henry VIIIPortrait of Henry VIII after Hans Holbein the Younger, c. 1537–1562King of EnglandLord/King of Ireland (more...) Reign22 April 1509 – 28 January 1547Coronation24 June 1509PredecessorHenry VIISuccessorEdward VIBorn28 June 1491Palace of Placentia, Greenwich, EnglandDied28 January 1547 (aged 55)Palace of Whitehall, Westminster, EnglandBurial16 February 1547St George's Chapel, Windsor Castl...
2023 book by Philip Snow China and Russia: Four Centuries of Conflict and Concord CountryUnited StatesLanguageEnglishSubjectGeopoliticsGenreNonfictionPublished25 April 2023PublisherYale University Press[1]Media typeHardcoverPages624ISBN978-0300166651 China and Russia: Four Centuries of Conflict and Concord is a non-fiction book by Philip Snow. Background The book examines the historical relationship between China and Russia over a span of four centuries. The book delves into the ...
2016 Hong Kong ePrix Race 1 of 12 of the 2016–17 Formula E Championship← Previous raceNext race → Race details[1][2]Date 9 October 2016Official name 2016 FIA Formula E HKT Hong Kong ePrix[3]Location Hong Kong Central Harbourfront Circuit, Hong KongCourse Street circuitCourse length 1.860 km (1.155 miles)Distance 45 laps, 83.700 km (51.795 miles)Weather WarmAttendance 30,000Pole positionDriver Nelson Piquet Jr. NextEV NIOTime 1:03.099Fastest la...
Equestrian at the Olympics Team dressageat the Games of the XXIII OlympiadVenueSanta Anita RacetrackDate8–9 AugustCompetitors36 (12 teams) from 12 nationsMedalists Reiner Klimke Uwe Sauer Herbert Krug West Germany Otto Hofer Christine Stückelberger Amy-Cathérine de Bary Switzerland Ulla Håkansson Ingamay Bylund Louise Nathhorst Sweden← 19801988 → Equestrian at the1984 Summer OlympicsDressageindividualteamEventingindividualteamJumpingindiv...
2003 film by F. Gary Gray For other uses, see The Italian Job (disambiguation). The Italian JobTheatrical release posterDirected byF. Gary GrayScreenplay by Donna Powers Wayne Powers Based onThe Italian Job1969 filmby Troy Kennedy MartinProduced byDonald De LineStarring Mark Wahlberg Charlize Theron Edward Norton Seth Green Jason Statham Mos Def Franky G Donald Sutherland CinematographyWally PfisterEdited by Richard Francis-Bruce Christopher Rouse Music byJohn PowellProductioncompanyDe Line P...
Second-level administrative divisions of Sri Lanka Districts of Sri LankaCategorySecond level administrative divisionLocationSri LankaNumber25Populations92,238–2,324,349Areas699–7,179 km²GovernmentDistrict secretariatSubdivisionsD.S. divisions This article contains Indic text. Without proper rendering support, you may see question marks or boxes, misplaced vowels or missing conjuncts instead of Indic text. Administrative divisionsof Sri Lanka First level Provinces Second level Distri...
American TV series or program Murder in Boston: Roots, Rampage, and ReckoningDirected byJason HehirCountry of originUnited StatesOriginal languageEnglishNo. of episodes1ProductionExecutive producers Joie Jacoby Linda Pizzuti Henry Dan Krockmalnic Nancy Abraham Lisa Heller Sara Rodriguez Producers Jason Hehir Jake Rogal Nicholas Eisenberg Jillian Moossmann Running time54 minutesProduction companies HBO Documentary Films The Boston Globe Little Room Films Original releaseNetworkHBOReleaseD...
Coastal schooners at Cape Jellison c. 1908 Cape Jellison is a 1,600-acre (6.5 km2) peninsula that juts into Penobscot Bay on the coast of Maine. In colonial times it was known as Wasaumkeag Point. It is part of the town of Stockton Springs, between Searsport and Bucksport, in the upper mid-coast region of the state. It was the site of the first port facility built by the Bangor and Aroostook Railroad. Fort Point State Park Main article: Fort Point State Park Maine's 120-acre (0.49 k...
Elena Nekrasova in Osessa, Ukraine, 2009 Elena Nekrasova (Russian: Елена Анатольевна Некрасова; born 1964) is a Russian writer, filmmaker and contemporary artist. Exhibitions of her paintings took place in Ukraine, Russia, United States, Japan, Germany, Denmark, Poland and other paintings are in many museums and private collections.[1][2][3][4] Elena Nekrasovа creates documentary films and video art. Documentary series Provincial museu...
Strategi Solo vs Squad di Free Fire: Cara Menang Mudah!