469,291 Members | 1,733 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,291 developers. It's quick & easy.

Railroad track syntax diagrams

Back in the mid-90's, Kees Blom generated a set of railroad syntax diagrams
for Python
(http://python.project.cwi.nl/search/...4q3/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
Aug 1 '06 #1
6 4416
Paul McGuire <pt***@austin.rr._bogus_.comwrote:
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.
Aug 1 '06 #2
On 2006-08-01, Roy Smith <ro*@panix.comwrote:
Paul McGuire <pt***@austin.rr._bogus_.comwrote:
>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.
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.

--
Grant Edwards grante Yow! I always liked FLAG
at DAY!!
visi.com
Aug 1 '06 #3

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/...4q3/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.d...skell/ebnf2ps/
http://www.antlr.org/share/1107033888258/SDG2-1.5.zip

- Paddy.

Aug 1 '06 #4

Paddy wrote:
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/...4q3/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.d...skell/ebnf2ps/
http://www.antlr.org/share/1107033888258/SDG2-1.5.zip

- Paddy.
And this suite includes a digram generator:

http://www.research.philips.com/tech...ant/index.html

- Pad.

Aug 1 '06 #5
Paddy wrote:
I googlled and got these:
http://www.informatik.uni-freiburg.d...skell/ebnf2ps/
http://www.antlr.org/share/1107033888258/SDG2-1.5.zip
There is another beast, also called ebnf2ps, but in elisp
(runs inside the editor).

It requires no additional software (i.e. no ghc) and is simpler
to use (no questions about inexistent .afm files etc.)

Ralf
Aug 2 '06 #6
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

Aug 3 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by sams | last post: by
2 posts views Thread by Irlan agous | last post: by
14 posts views Thread by Uwe Mayer | last post: by
4 posts views Thread by Bob Stearns | last post: by
4 posts views Thread by PIEBALD | last post: by
4 posts views Thread by Ole Nielsby | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.