Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Extended Backus–Naur form
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Basics== EBNF is a [[code]] that expresses the [[syntax]] of a formal language.<ref>{{cite web |last=Pattis |first=Richard E. |author-link=Richard E. Pattis |date=2013-08-12<!--from PDF properties--> |title=EBNF: A Notation to Describe Syntax |url=http://www.ics.uci.edu/~pattis/misc/ebnf2.pdf |website=ICS.UCI.edu |publisher=[[University of California, Irvine]] |page=1 |access-date=2025-05-18 }}</ref> An EBNF consists of [[Terminal and nonterminal symbols#Terminal symbols|terminal symbol]]s 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 [[Alphanumerics|alphanumeric characters]], [[Punctuation|punctuation marks]], and [[whitespace character]]s. The EBNF defines [[Production (computer science)|production rules]] where sequences of symbols are respectively assigned to a [[Terminal and nonterminal symbols#Nonterminal symbols|nonterminal]]: <syntaxhighlight lang="ebnf"> digit excluding zero = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; digit = "0" | digit excluding zero ; </syntaxhighlight> 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: <syntaxhighlight lang="ebnf"> twelve = "1", "2" ; two hundred one = "2", "0", "1" ; three hundred twelve = "3", twelve ; twelve thousand two hundred one = twelve, two hundred one ; </syntaxhighlight> Expressions that may be omitted or repeated can be represented through curly braces { ... }: <syntaxhighlight lang="ebnf"> positive integer = digit excluding zero, { digit } ; </syntaxhighlight> 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: <syntaxhighlight lang="ebnf"> integer = "0" | [ "-" ], positive integer ; </syntaxhighlight> Therefore, an [[integer]] is a zero (''0'') or a [[positive integer]] that may be preceded by an optional [[Plus and minus signs#Minus sign|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. {| class="wikitable" |- ! Usage ! Notation ! Alternative ! Meaning |- | definition | style="text-align:center" | {{mono|{{=}}}} | | |- | [[concatenation]] | style="text-align:center" | {{mono|,}} | | |- | termination | style="text-align:center" | {{mono|;}} | style="text-align:center" | {{Mono|.}} | |- | [[alternation (formal language theory)|alternation]] | style="text-align:center" | {{mono|{{!}}}} | style="text-align:center" | {{Mono|/ or !}} | |- | optional | style="text-align:center" | {{mono|[ ... ]}} | style="text-align:center" | {{Mono|(/ ... /)}} | style="text-align:center" | none or once |- | repetition | style="text-align:center" | {{mono|{ ... } }} | style="text-align:center" | {{Mono|(: ... :)}} | style="text-align:center" | none or more |- | grouping | style="text-align:center" | {{mono|( ... )}} | | |- | terminal string | style="text-align:center" | {{mono|" ... "}} | style="text-align:center" | {{mono|' ... '}} | |- | comment | style="text-align:center" | {{mono|(* ... *)}} | | |- | special sequence | style="text-align:center" | {{mono|? ... ?}} | | |- | exception | style="text-align:center" | {{mono|-}} | | |}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)