Wirth syntax notation (WSN) is a metasyntax, that is, a formal way to describe formal languages. Originally proposed by Niklaus Wirth in 1977 as an alternative to Backus–Naur form (BNF). It has several advantages over BNF in that it contains an explicit iteration construct, and it avoids the use of an explicit symbol for the empty string (such as <empty> or ε).
WSN has been used in several international standards, starting with ISO 10303-21. It was also used to define the syntax of EXPRESS, the data modelling language of STEP.
The equals sign indicates a production. The element on the left is defined to be the combination of elements on the right. A production is terminated by a full stop (period).
We take these concepts for granted today, but they were novel and even controversial in 1977. Wirth later incorporated some of the concepts (with a different syntax and notation) into extended Backus–Naur form.
Notice that letter
and character
are left undefined. This is because numeric characters (digits 0 through 9) may be included in both definitions or excluded from one, depending on the language being defined, e.g.:
If character
goes on to include digit
and other printable ASCII characters, then it diverges even more from letter
, which one can assume does not include the digit characters or any of the special (non-alphanumeric) characters.
The syntax of BNF can be represented with WSN as follows, based on translating the BNF example of itself:
This definition appears overcomplicated because the concept of "optional whitespace" must be explicitly defined in BNF, but it is implicit in WSN. Even in this example, text
is left undefined, but it is assumed to mean "ASCII-character { ASCII-character }
". (EOL
is also left undefined.) Notice how the kludge "<" rule-name ">"
has been used twice because text
was not explicitly defined.