Declarative Objectivity (DO) Language : Syntax Diagrams and Production Rules
Syntax Diagrams and Production Rules
Major language constructs are presented using both “railroad” diagrams and BNF-like production rules. The two presentations are meant to be equivalent.
BNF
The notation used here is an informal version of EBNF.
Alphanumeric characters that are meant to be reproduced literally (terminal symbols) are not enclosed in quotation marks; it should be clear from context, including the examples, which characters are terminals.
Non-alphanumeric terminals (such as commas or curly braces) are always enclosed in quotation marks.
An unquoted asterisk symbol (*) indicates 0 or more occurrences of the symbol it follows.
An unquoted plus sign (+) indicates 1 or more occurrences of the symbol it follows.
An unquoted question mark (?) indicates 0 or 1 occurrences of the symbol it follows.
For example, the following rule shows how to form a conjunction of arbitrary length by alternating conjuncts with and.
conjunction : conjunct (AND conjunct)*;
The following rules show how to represent whole numbers using the North American convention of three-digit groups separated by commas (e.g 100,000).
wholeNumber : digit (digit)? (digit)? (',' digit digit digit)*;
digit : 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
Syntax Diagrams
Each diagram begins and ends with an arrow and consists of a sequence of lozenges connected by arrows. The lozenges represent elements that are concatenated to form the construct defined by the diagram. (The connecting arrows can be read as “followed by”.) Forming a valid instance of the construct requires tracing a full path through the diagram, from the initial arrow to the exit arrow.
Simple left-to-right arrows connect elements that must be included within a subsequence. For example, the following diagram shows how to form the word cat from the letters C, A, and T.
Cat : C A T;
Note:For the purposes of these “spelling” illustrations, we are ignoring the whitespace that would normally separate elements within an instance of the construct.
Arrows that bypass an element or subsequence by detouring below it indicate that the bypassed element or subsequence is optional. For example, the following diagram shows how to spell the word color (or colour).
Color : C O L O U? R;
And the following diagram shows how to spell catalog (or catalogue).
Catalog : C A T A L O G (U E)?;
Branching subsequences arranged in parallel, one below the other, indicate alternative ways of forming the larger construct. Thus the following diagram shows how to spell the word gray (or grey).
Gray : G R (A | E) Y;
Boldface monospace type represents text, such as keywords and language primitives, that appears exactly as it would in a DO statement. Other type styles represent subcontstructs that are defined by further syntax diagrams (either on the same page or elsewhere in the documentation).
Arrows that loop backward (right to left) above a subsequence indicate that the subsequence can be repeated.
For example, the following diagrams show how to form a floating-point numeral in decimal notation.
Decimal : digits '.' digits;
digits : digit (digit)*;
digit : 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;