Railroad track syntax diagrams

P

Paul McGuire

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
 
R

Roy Smith

Paul McGuire said:
For those who are not familiar with railroad syntax diagrams, they
show a grammar's syntax using arrows and blocks, instead of BNF

I've always liked railroad diagrams. Oracle used to use them (maybe
they still do?) in their SQL reference manuals. I find them much
easier to understand than BNF.
 
G

Grant Edwards

I've always liked railroad diagrams.

Me too. The Pascal text we used 25 years ago had a section in
the back with railroad diagrams, and a section with BNF. I
never ran into anybody who preferred the BNF.
 
P

Paddy

Paul said:
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.
 
P

Paddy

Paddy said:
Paul said:
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.

And this suite includes a digram generator:

http://www.research.philips.com/technologies/syst_softw/elegant/index.html

- Pad.
 
B

bearophileHUGS

Paul McGuire:
generation of the railroad diagrams (in something
more legible/appealing than ASCII-art!).

That ASCII-art looks easy enough to read. It may be bad when the graph
becomes very big.

Bye,
bearophile
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,787
Messages
2,569,629
Members
45,331
Latest member
ElaneLyttl

Latest Threads

Top