Railroad track syntax diagrams

Paddy paddy3118 at netscape.net
Tue Aug 1 15:05:09 EDT 2006


Paul McGuire wrote:
> Back in the mid-90's, Kees Blom generated a set of railroad syntax diagrams
> for Python
> (http://python.project.cwi.nl/search/hypermail/python-1994q3/0286.html).
> This pre-dates any Python awareness on my part, but I'm sure this would have
> been version 1.3 or something.
>
> For those who are not familiar with railroad syntax diagrams, they show a
> grammar's syntax using arrows and blocks, instead of BNF - here's an excerpt
> from the Python grammar, plus "ASCII-art" diagrams - must be viewed in
> non-prop font to be appreciated:
>
> suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
>
> ----+--> simple_stmt --------------------------------->\
>     |                                                   |
>     \--> NEWLINE --> INDENT --+--> stmt --+--> DEDENT --+-->
>                              /            |
>                              \----<-------/
>
> if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
>
>
> --> 'if' -> test --> ':' --> suite -->+
>                                       |
>       ------------<-------------------+
>      /
>     +
>     | ------------<------------------------
>     |/                                     \
>     +                                      |
>     |                                      |
>     +-> 'elif' -> test -> ':' --> suite -->/
>     |
>     |
>     +-> 'else' -> ':' --> suite -->
>     |                              \
>     \---------------->--------------+------->
>
>
> I was recently contacted by a volunteer in Banda Aceh teaching tsunami
> refugees how to program in Python (new job skills and all that), and he
> asked if there were any updated versions of these diagrams, or if it would
> be difficult to generate them anew.   It seems that railroad diagrams are
> nice and unambiguous for his students to use, in the face of verbal language
> barriers.
>
> I have written a pyparsing parser that reads the grammar file that ships
> with Python - the parser is included in the latest release of pyparsing, and
> also online at the pyparsing.wikispaces.com - but I have no graph-generating
> tools to go the next step: generation of the railroad diagrams (in something
> more legible/appealing than ASCII-art!).
>
> Anyone interested in helping complete this last step?
>
> Thanks,
> -- Paul
I googlled and got these:
  http://www.informatik.uni-freiburg.de/~thiemann/haskell/ebnf2ps/
  http://www.antlr.org/share/1107033888258/SDG2-1.5.zip

- Paddy.




More information about the Python-list mailing list