Extended Backus–Naur form

In computer science, extended Backus–Naur form (EBNF) is a family of metasyntax notations, any of which can be used to express a context-free grammar. EBNF is used to make a formal description of a formal language such as a computer programming language. They are extensions of the basic Backus–Naur form (BNF) metasyntax notation. The earliest EBNF was developed by Niklaus Wirth, incorporating some of the concepts (with a different syntax and notation) from Wirth syntax notation. Today, many variants of EBNF are in use. The International Organization for Standardization adopted an EBNF Standard, ISO/IEC 14977, in 1996. [1] [2] According to Zaytsev, however, this standard "only ended up adding yet another three dialects to the chaos" and, after noting its lack of success, also notes that the ISO EBNF is not even used in all ISO standards. [3] Wheeler argues against using the ISO standard when using an EBNF and recommends considering alternative EBNF notations such as the one from the W3C Extensible Markup Language (XML) 1.0 (Fifth Edition). [4] This article uses EBNF as specified by the ISO for examples applying to all EBNFs. Other EBNF variants use somewhat different syntactic conventions.

Basics

EBNF is a code that expresses the syntax of a formal language.[5] An EBNF consists of terminal symbols and non-terminal production rules which are the restrictions governing how terminal symbols can be combined into a valid sequence. Examples of terminal symbols include alphanumeric characters, punctuation marks, and whitespace characters.

The EBNF defines production rules where sequences of symbols are respectively assigned to a nonterminal:

digit excluding zero = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
digit                = "0" | digit excluding zero ;

This production rule defines the nonterminal digit which is on the left side of the assignment. The vertical bar represents an alternative and the terminal symbols are enclosed with quotation marks followed by a semicolon as terminating character. Hence a digit is a 0 or a digit excluding zero that can be 1 or 2 or 3 and so forth until 9.

A production rule can also include a sequence of terminals or nonterminals, each separated by a comma:

twelve                          = "1", "2" ;
two hundred one                 = "2", "0", "1" ;
three hundred twelve            = "3", twelve ;
twelve thousand two hundred one = twelve, two hundred one ;

Expressions that may be omitted or repeated can be represented through curly braces { ... }:

natural number = digit excluding zero, { digit } ;

In this case, the strings 1, 2, ..., 10, ..., 10000, ... are correct expressions. To represent this, everything that is set within the curly braces may be repeated arbitrarily often, including not at all.

An option can be represented through squared brackets [ ... ]. That is, everything that is set within the square brackets may be present just once, or not at all:

integer = "0" | [ "-" ], natural number ;

Therefore, an integer is a zero (0) or a natural number that may be preceded by an optional minus sign.

EBNF also provides, among other things, the syntax to describe repetitions (of a specified number of times), to exclude some part of a production, and to insert comments in an EBNF grammar.

Table of symbols

The following represents a proposed ISO/IEC 14977 standard, by R. S. Scowen, page 7, tables 1 and 2.

Usage Notation Alternative Meaning
definition =
concatenation ,
termination ; .
alternation | / or !
optional [ ... ] (/ ... /) none or once
repetition { ... } (: ... :) none or more
grouping ( ... )
terminal string " ... " ' ... '
comment (* ... *)
special sequence ? ... ?
exception -


Examples

Syntax diagram

One possible EBNF syntax diagram
One possible EBNF syntax diagram

EBNF

Even EBNF can be described using EBNF. Consider below grammar (using conventions such as "-" to indicate set disjunction, "+" to indicate one or more matches, and "?" for optionality):

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 = "[" | "]" | "{" | "}" | "(" | ")" | "<" | ">"
       | "'" | '"' | "=" | "|" | "." | "," | ";" | "-" 
       | "+" | "*" | "?" | "\n" | "\t" | "\r" | "\f" | "\b" ;

character = letter | digit | symbol | "_" | " " ;
identifier = letter , { letter | digit | "_" } ;

S = { " " | "\n" | "\t" | "\r" | "\f" | "\b" } ;

terminal = "'" , character - "'" , { character - "'" } , "'"
         | '"' , character - '"' , { character - '"' } , '"' ;

terminator = ";" | "." ;

term = "(" , S , rhs , S , ")"
     | "[" , S , rhs , S , "]"
     | "{" , S , rhs , S , "}"
     | terminal
     | identifier ;

factor = term , S , "?"
       | term , S , "*"
       | term , S , "+"
       | term , S , "-" , S , term
       | term , S ;

concatenation = ( S , factor , S , "," ? ) + ;
alternation = ( S , concatenation , S , "|" ? ) + ;

rhs = alternation ;
lhs = identifier ;

rule = lhs , S , "=" , S , rhs , S , terminator ;

grammar = ( S , rule , S ) * ;

Pascal

A Pascal-like programming language that allows only assignments can be defined in EBNF as follows:

 (* a simple program syntax in EBNF - Wikipedia *)
 program = 'PROGRAM', white space, identifier, white space, 
            'BEGIN', white space, 
            { assignment, ";", white space },
            'END.' ;
 identifier = alphabetic character, { alphabetic character | digit } ;
 number = [ "-" ], digit, { digit } ;
 string = '"' , { all characters - '"' }, '"' ;
 assignment = identifier , ":=" , ( number | identifier | string ) ;
 alphabetic character = "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" ;
 white space = ? white space characters ? ;
 all characters = ? all visible characters ? ;

For example, a syntactically correct program then could be:

 PROGRAM DEMO1
 BEGIN
   A:=3;
   B:=45;
   H:=-100023;
   C:=A;
   D123:=B34A;
   BABOON:=GIRAFFE;
   TEXT:="Hello world!";
 END.

The language can easily be extended with control flows, arithmetical expressions, and Input/Output instructions. Then a small, usable programming language would be developed.

Advantages over BNF

Any grammar defined in EBNF can also be represented in BNF, though representations in the latter are generally lengthier. E.g., options and repetitions cannot be directly expressed in BNF and require the use of an intermediate rule or alternative production defined to be either nothing or the optional production for option, or either the repeated production of itself, recursively, for repetition. The same constructs can still be used in EBNF.

The BNF uses the symbols (<, >, |, ::=) for itself, but does not include quotes around terminal strings. This prevents these characters from being used in the languages, and requires a special symbol for the empty string. In EBNF, terminals are strictly enclosed within quotation marks ("..." or '...'). The angle brackets ("<...>") for nonterminals can be omitted.

BNF syntax can only represent a rule in one line, whereas in EBNF a terminating character, the semicolon character “;” marks the end of a rule.

Furthermore, EBNF includes mechanisms for enhancements, defining the number of repetitions, excluding alternatives, comments, etc.

Conventions

  1. According to the section 4 of the ISO/IEC 14977 standard, the following conventions are used:
    • Each meta-identifier of Extended BNF is written as one or more words joined together by hyphens. However, joining the words seems to apply only to referencing meta-identifiers outside of the metalanguage itself, as seen in the examples of the standard.
    • A meta-identifier ending with -symbol is the name of a terminal symbol of Extended BNF.
  2. The normal character representing each operator of Extended BNF and its implied precedence is (highest precedence at the top):
     * repetition-symbol
     - except-symbol
     , concatenate-symbol
     | definition-separator-symbol
     = defining-symbol
     ; terminator-symbol
     . terminator-symbol
    
  3. The normal precedence is overridden by the following bracket pairs:
     (* start-comment-symbol          end-comment-symbol *)
     '  first-quote-symbol            first-quote-symbol  '
     (  start-group-symbol              end-group-symbol  )
     [  start-option-symbol            end-option-symbol  ]
     {  start-repeat-symbol            end-repeat-symbol  }
     ?  special-sequence-symbol  special-sequence-symbol  ?
     "  second-quote-symbol          second-quote-symbol  "
    
    The first-quote-symbol is the apostrophe as defined by ISO/IEC 646:1991, that is to say Unicode U+0027 ('); the font used in ISO/IEC 14977:1996(E) renders it very much like the acute, Unicode U+00B4 (´), so confusion sometimes arises. However, the ISO Extended BNF standard invokes ISO/IEC 646:1991, "ISO 7-bit coded character set for information interchange", as a normative reference and makes no mention of any other character sets, so formally, there is no confusion with Unicode characters outside the 7-bit ASCII range.

As examples, the following syntax rules illustrate the facilities for expressing repetition:

aa = "A";
bb = 3 * aa, "B";
cc = 3 * [aa], "C";
dd = {aa}, "D";
ee = aa, {aa}, "E";
ff = 3 * aa, 3 * [aa], "F";
gg = {3 * aa}, "G";
hh = (aa | bb | cc), "H";

Terminal strings defined by these rules are as follows:

aa: A
bb: AAAB
cc: C AC AAC AAAC
dd: D AD AAD AAAD AAAAD etc.
ee: AE AAE AAAE AAAAE AAAAAE etc.
ff: AAAF AAAAF AAAAAF AAAAAAF
gg: G AAAG AAAAAAG etc.
hh: AH AAABH CH ACH AACH AAACH

Extensibility

According to the ISO 14977 standard EBNF is meant to be extensible, and two facilities are mentioned. The first is part of EBNF grammar, the special sequence, which is arbitrary text enclosed with question marks. The interpretation of the text inside a special sequence is beyond the scope of the EBNF standard. For example, the space character could be defined by the following rule:

 space = ? ASCII character 32 ?;

The second facility for extension is using the fact that parentheses in EBNF cannot be placed next to identifiers (they must be concatenated with them). The following is valid EBNF:

 something = foo, ( bar );

The following is not valid EBNF:

 something = foo ( bar );

Therefore, an extension of EBNF could use that notation. For example, in a Lisp grammar, function application could be defined by the following rule:

 function application = list( symbol, { expression } );
  • The W3C publishes an EBNF notation.
  • The W3C used a different EBNF to specify the XML syntax.
  • The British Standards Institution published a standard for an EBNF: BS 6154 in 1981.
  • The IETF uses augmented BNF (ABNF), specified in RFC 5234.

See also

References

  1. ^ Roger S. Scowen: Extended BNF — A generic base standard. Software Engineering Standards Symposium 1993.
  2. ^ International standard (ISO 14977), which is one of many formats for EBNF, is now freely available as Zip-compressed PDF file.
  3. ^ Zaytsev, Vadim (March 26–30, 2012). "BNF Was Here: What Have We Done About the Unnecessary Diversity of Notation for Syntactic Definitions?" (PDF). Proceedings of the 27th Annual ACM Symposium on Applied Computing (SAC '12). Riva del Garda, Italy. p. 1.
  4. ^ Wheeler, David A. (2019). "Don't Use ISO/IEC 14977 Extended Backus-Naur Form (EBNF)". Retrieved 2021-02-26.
  5. ^ Pattis, Richard E. "EBNF: A Notation to Describe Syntax" (PDF). ICS.UCI.edu. University of California, Irvine. p. 1. Retrieved 2021-02-26.

Read other articles:

Front Pembebasan Nasional Angola Frente Nacional de Libertação de AngolaPresidenNgola KabanguPendiriHolden RobertoDibentuk1954 (sebagai gerakan gerilya União dos Povos do Norte de Angola)1959 (sebagai gerakan gerilya União dos Povos de Angola)1961 (sebagai gerakan gerilya FNLA)1992 (sebagai sebuah partai)Kantor pusatLuanda, Republik AngolaIdeologiNasionalisme sipil[1]Demokrasi Kristen[1]Konservatisme[2]Posisi politikKanan tengahKursi dalam Majelis Nasional2 / ...

RostovNama lengkapФутбольный клуб Ростов(Football Club Rostov)JulukanSelmashiBerdiri1930; 93 tahun lalu (1930)StadionOlimp-2(Kapasitas: 15.840)PemilikOblast RostovKetuaViktor GoncharovManajer Ivan DaniliantsLigaLiga Utama Rusia2015–16ke–2Situs webSitus web resmi klub Kostum kandang Kostum tandang FC Rostov (bahasa Rusia: Футбольный клуб Ростов) adalah tim sepak bola Rusia yang berbasis di Rostov-on-Don, Oblast Rostov.Klub yang didirika...

Gaso o alconafta es la mezcla de gasolina y alcohol en distintas proporciones, para uso como combustible en motores de explosión diseñados para quemar derivados del petróleo. Se puede realizar la mezcla del gasohol con alcohol etílico (etanol) o con alcohol metílico (metanol), aunque el etanol es el tipo de alcohol que más se ha utilizado comercialmente. El metanol se ha utilizado en forma más limitada debido a que es tóxico. El uso más común del término gasohol se refiere a la mez...

LoganKarya seni untuk sampul Wolverine vol. 3, 66 (Januari, 2010Templat:Descript-cvr/pub). Seni oleh Michael Turner.Informasi publikasiPenerbitMarvel ComicsPenampilan pertamaFantastic Four #558 (Agustus 2008)Dibuat oleh Mark Millar Steve McNiven (berdasarkan Wolverine oleh Len Wein, John Romita, Sr., dan Herb Trimpe) Informasi dalam ceritaAlter egoJames Logan HowlettAfiliasi tim X-Men Fantastic Force Kemampuan Indra super, kekuatan, kecepatan, daya tahan, refleks, stamina Usia panja...

Perodua AxiaInformasiProdusenPeroduaMasa produksi2014–kiniModel untuk tahun2014–kiniPerakitanRawang, Selangor, MalaysiaBodi & rangkaKelasKei car / segmen-ABentuk kerangkahatchback lima pintuTata letakMesin depanMobil terkaitDaihatsu AylaToyota AgyaPenyalur dayaMesin1.0L 1KR-DE DOHC l3TransmisiTransmisi manual 5-kecepatan4-kecepatan otomatisDimensiJarak sumbu roda2.450 mm (96,5 in)Panjang3.640 mm (143,3 in)Lebar1.620 mm (63,8 in)Tinggi1.510 ...

Stasiun Kokubo国母駅Stasiun JR Kokubo, Januari 2006Lokasi310 Saijō, Shōwa-machi, Nakakoma-gun, Yamanashi-kenJepangKoordinat35°37′49″N 138°33′07″E / 35.6304°N 138.5520°E / 35.6304; 138.5520Pengelola JR CentralJalur Jalur MinobuLetak dari pangkal81.2 kilometer dari FujiJumlah peron1 peron pulauInformasi lainStatusTanpa stafSejarahDibuka30 Maret 1928Penumpang2016438 per hari Lokasi pada petaStasiun KokuboLokasi di Prefekfur YamanashiTampilkan peta Prefekf...

Перуанская коммунистическая партияисп. Partido Comunista Peruano Лидер Роберто де ла Крус Уаман Основатель Хосе Карлос Мариатеги Основана 7 октября 1928 года Штаб-квартира Лима Страна  Перу Идеология марксизм-ленинизм Интернационал Международная встреча коммунистических и ра�...

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Braamfontein – news · newspapers · books · scholar · JSTOR (September 2014) (Learn how and when to remove this template message) Place in Gauteng, South AfricaBraamfonteinBraamfonteinShow map of GautengBraamfonteinShow map of South AfricaBraamfonteinShow map of...

This biography of a living person needs additional citations for verification. Please help by adding reliable sources. Contentious material about living persons that is unsourced or poorly sourced must be removed immediately from the article and its talk page, especially if potentially libelous.Find sources: Delores M. Etter – news · newspapers · books · scholar · JSTOR (February 2013) (Learn how and when to remove this template message) Delores M. Ett...

  لمعانٍ أخرى، طالع قلعة سفيد (توضيح). قلعة سفيد (مندلي) قلعه سفيد  - قلعة أثرية -  تقسيم إداري البلد  العراق المحافظة ديالى مندلي إحداثيات 33°44′00″N 45°33′18″E / 33.73333°N 45.555°E / 33.73333; 45.555 معلومات أخرى التوقيت توقيت العراق (+3 غرينيتش) توقيت صيفي توقيت () �...

Season of television series Season of television series Grey's AnatomySeason 7DVD cover art for the seventh season ofGrey's AnatomyStarring Ellen Pompeo Sandra Oh Justin Chambers Chandra Wilson James Pickens, Jr. Sara Ramirez Eric Dane Chyler Leigh Kevin McKidd Jessica Capshaw Kim Raver Sarah Drew Jesse Williams Patrick Dempsey Country of originUnited StatesNo. of episodes22ReleaseOriginal networkABCOriginal releaseSeptember 23, 2010 (2010-09-23) –May 19, 2011 (2011-05-19...

1991 single by Guns N' Roses For other uses, see Don't Cry (disambiguation). Don't CrySingle by Guns N' Rosesfrom the album Use Your Illusion I and II B-sideDon't Cry (alt. lyrics) (LP version)ReleasedSeptember 1991StudioA&MRecord PlantStudio 56Image RecordingConway RecordingMetalworks RecordingGenreHard rock[1]Length4:45LabelGeffenSongwriter(s) Axl Rose Izzy Stradlin Producer(s) Mike Clink Guns N' Roses Guns N' Roses singles chronology You Could Be Mine (1991) Don't Cry (1991) Li...

2008 studio album by Cradle of FilthGodspeed on the Devil's ThunderCover art by David HoStudio album by Cradle of FilthReleased28 October 2008RecordedMarch–June 2008 at Backstage Studios, Derbyshire, EnglandGenreExtreme metalLength71:22LabelRoadrunnerProducer Andy Sneap Doug Cook Cradle of Filth Cradle of Filth chronology Thornography(2006) Godspeed on the Devil's Thunder(2008) Darkly, Darkly, Venus Aversa(2010) Singles from Godspeed on the Devil's Thunder Tragic KingdomReleased: 20...

New World Development Тип public limited company Листинг на бирже SEHK: 0017[1] Основание 29 мая 1970[2] Основатели Cheng Yu-tung[d] Расположение Гонконг, Китай Отрасль конгломерат Продукция недвижимость[d] Сайт nwd.com.hk  Медиафайлы на Викискладе New World Centre в Гонконге Универмаг New World Department Store в Гонк...

1997 studio album by Chet Atkins and Tommy EmmanuelThe Day Finger Pickers Took Over the WorldStudio album by Chet Atkins and Tommy EmmanuelReleased11 March 1997StudioCA Workshop, Nashville, TennesseeGenre Bluegrass jazz easy listening Length36:02LabelColumbia[1]Chet Atkins chronology Almost Alone(1996) The Day Finger Pickers Took Over the World(1997) Guitar Legend: The RCA Years(2000) Tommy Emmanuel chronology Can't Get Enough(1996) The Day Finger Pickers Took Over the World(1...

Artikel ini sebatang kara, artinya tidak ada artikel lain yang memiliki pranala balik ke halaman ini.Bantulah menambah pranala ke artikel ini dari artikel yang berhubungan atau coba peralatan pencari pranala.Tag ini diberikan pada November 2022. Dirk I dari BelandaPangeran FrisiaDirk I seperti yang digambarkan pada abad ke-16Berkuasauncertain – 928/944PendahuluGerolfPenerusDirk IIPemakamanBiara EgmondAyahpossibly Gerolf or Radbod, Pangeran FrisiaPermaisuriGevaAnakDirk II Dirk I (Theoderic) ...

West End theatre in Covent Garden, London Theatre Royal, Drury LaneExterior of venue during a production of Charlie and the Chocolate FactoryAddressCatherine StreetLondon, WC2EnglandCoordinates51°30′47″N 00°07′13″W / 51.51306°N 0.12028°W / 51.51306; -0.12028Public transit Covent GardenOwnerLW TheatresDesignationGrade I listedCapacity1,996 (4 levels)ProductionFrozenConstructionOpened1663; 360 years ago (1663) (original structure)Rebuilt 167...

American program with college-level classes offered to high school students Advanced Placement examsLogo since 2017AcronymAPDeveloper / administratorCollege BoardYear started1952 (1952)DurationMostly 2–3 hours[1]Score / grade range1–5 (details)Score / grade validityScores archived after 4 years, but remain valid[2]OfferedYearlyFee2024 exams (USD):[3] $98 (US, Canada, DoDEA schools)$128 (elsewhere)$146 (AP Capstone)Websiteap.collegeboard.org This article is par...

Movie theater chain in the western United States This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Century Theatres – news · newspapers · books · scholar · JSTOR (December 2011) (Learn how and when to remove this template message) Century TheatresA Century Theatre multiplex in Portland, Oregon, seen at nightTy...

Se denomina reloj analógico al que indica la hora en una circunferencia numerada, mediante manecillas o agujas que indican la hora, los minutos y en algunos relojes, los segundos. Se designa un reloj como analógico al que tiene estas características independientemente que su funcionamiento sea mecánico, eléctrico o electrónico, por oposición a los relojes digitales Esfera del reloj analógico En la esfera del reloj analógico, podemos ver en su parte exterior la numeración de las hora...