3. BNF
Contents
Abbreviation for Backus-Naur form.
BNF is a metalanguage used to define the syntax of a programming language.
It uses the following symbols:
4. BNF
Contents examples
This translates into English as:
•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 "jr-part" (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/or initials).
•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.
Note that many things (such as the format of a first-name, apartment specifier, ZIP-code, and Roman numeral) are left unspecified here.
If necessary, they may be described using additional BNF rules.
5. EBNF
Contents
Abbreviation for extended Backus-Naur form.
EBNF is a metalanguage used to define the syntax of a programming language.
In this extended form the following symbols are used:
Interpretation:
An identifier is defined to be a Letter followed by one or more
Letters or Digits.
Letter is a non-terminal symbol and is defined elsewhere, and
Digit is another non-terminal symbol defined elsewhere.
7. Railroad diagram
Contents
This is an alternative, graphical method used to
define the syntax of a programming language.
• Rectangles are used to enclose non-terminal symbols
(that is, symbols that will be further defined).
• Circles or rounded rectangles are used to enclose terminal symbols.
These elements are linked by paths to show all legal combinations.
1. By starting at the left-hand side of the diagram and
2. tracing any path in a forward direction
3. to reach the right-hand side of the diagram,
4. a syntactically correct construct will be covered.
(‘Railroad’ in this context means a branch in the diagram is legal if it is treated as a set of
points in a railroad layout and a train can take the branch in a forward direction only).