See javascript-flow-diagram-tools

Railroad diagrams: 

The rules for interpreting these diagrams are simple:

1. You start on the left edge and follow the tracks to the right edge.

2. As you go, you will encounter literals in ovals, and rules or description
   in rectangles.

3. Any sequence that can be made by following the tracks is legal.

4. Any sequence that can not be made by following the tracks is not legal.

5. Railroad diagrams with one bar at each end allow whitespace to be inserted
   between any pair of token.  Railroad diagrams with two bars at each end
   do not.

See chapter 2 of "JavaScript: The Good Parts" for examples.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License