How to read railroad diagrams

Understand the syntax used in railroad diagrams that show syntax.

Each railroad diagram begins with a double right arrow and ends with a right and left arrow pair. Lines that begin with a single right arrow are continuation lines. You read a railroad diagram from left to right and from top to bottom, following the direction of the arrows.

The following examples show other conventions used in railroad diagrams.

This example shows that you must specify values A, B, and C. Required values are shown on the main line of a railroad diagram:
Read syntax diagramSkip visual syntax diagramABC
This shows that you can specify value A. Optional values are shown below the main line of a railroad diagram:
Read syntax diagramSkip visual syntax diagramA
The next example specifies that values A, B, and C are options, one of which you must specify:
Read syntax diagramSkip visual syntax diagramABC
Values A, B, and C are options in this example, one of which you can specify:
Read syntax diagramSkip visual syntax diagramABC
The next example shows that you can specify one or more of the values A, B, and C. Any required separator for multiple or repeated values (in this example, the comma (,)) is shown on the arrow:
Read syntax diagramSkip visual syntax diagram,ABC
In this example, you can specify value A multiple times. The separator in this example is optional:
Read syntax diagramSkip visual syntax diagram,A
Values A, B, and C are alternatives in the next example, one of which you can specify. If you specify none of the values shown, the default A (the value shown above the main line) is used:
Read syntax diagramSkip visual syntax diagramABC
The last example shows the use of a syntax fragment Name, which is shown separately from the main railroad diagram. This technique is used to simplify the diagram, or help fit it into the page of text. The fragment can be used multiple times in the railroad diagram:
Read syntax diagramSkip visual syntax diagramName
Name
Read syntax diagramSkip visual syntax diagramAB

Punctuation and uppercase values must be specified exactly as shown.

Lowercase values (for example, name) indicate where to type your own text in place of the name variable.