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
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!
==Structure== BNF specifications outline how symbols are combined to form syntactically valid sequences. Each BNF consists of three core components: a set of [[Nonterminal symbol|non-terminal symbols]], a set of [[Terminal symbol|terminal symbols]], and a series of derivation rules.<ref name="janikow2">{{cite web |last1=Janikow |first1=Cezary Z. |title=What is BNF? |url=http://www.cs.umsl.edu/~janikow/cs4280/bnf.pdf}}</ref> Non-terminal symbols represent categories or variables that can be replaced, while terminal symbols are the fixed, literal elements (such as keywords or punctuation) that appear in the final sequence. Derivation rules provide the instructions for replacing non-terminal symbols with specific combinations of symbols. A derivation rule is written in the format:<syntaxhighlight lang="bnf"> <symbol> ::= __expression__ </syntaxhighlight> where: * <code><[[symbol]]></code><ref name="class">{{cite web |last=Naur |first=Peter |date=1961 |title=A COURSE OF ALGOL 60 PROGRAMMING with special reference to the DASK ALGOL system |url=http://archive.computerhistory.org/resources/text/algol/ACM_Algol_bulletin/1064048/frontmatter.pdf |access-date=26 March 2015 |publisher=Regnecentralen |publication-place=Copenhagen}}</ref> is a non-terminal symbol, enclosed in angle brackets (<>), identifying the category to be replaced * {{Code|1=::=}} is a metasymbol meaning "is replaced by," * [[expression (mathematics)|<code>__expression__</code>]] is the replacement, consisting of one or more sequences of symbols—either terminal symbols (e.g., literal text like "Sr." or ",") or non-terminal symbols (e.g., {{Code|1=<last-name>|2=bnf}})—with options separated by a [[vertical bar]] (|) to indicate alternatives. For example, in the rule {{Code|1=<opt-suffix-part> ::= "Sr." {{!}} "Jr." {{!}} ""|2=bnf}}, the entire line is the derivation rule, "Sr.", "Jr.", and "" (an empty string) are terminal symbols, and {{Code|1=<opt-suffix-part>|2=bnf}} is a non-terminal symbol. Generating a valid sequence involves starting with a designated start symbol and iteratively applying the derivation rules.<ref name="janikow">{{cite web |last1=Janikow |first1=Cezary Z. |title=What is BNF? |url=http://www.cs.umsl.edu/~janikow/cs4280/bnf.pdf}}</ref> This process can extend sequences incrementally. To allow flexibility, some BNF definitions include an optional "delete" symbol (represented as an empty alternative, e.g., {{Code|1=<item> ::= <thing> {{!}}|2=bnf}} ), enabling the removal of certain elements while maintaining syntactic validity.<ref name="janikow" />
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)