By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,749 Members | 1,627 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,749 IT Pros & Developers. It's quick & easy.

Railroad track syntax diagrams

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a

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

P: n/a

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

P: n/a
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

P: n/a
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.