Rail Road Diagrams

I've been wanting to promote the usage of the Lua programming language, so I thought it would be nice to provide visual diagrams of the syntax to help new people who would not take the time to read BNF descriptions of the language. When I looked online for a solution to this problem, I found this description of how sqlite generates railroad diagrams by using a Tcl/Tk script. I also found these nice CSS diagrams which are "generated" with power point.
The Tcl/Tk solution is neat, but trying to describe the railroad diagrams in Tcl/Tk was difficult, and I don't have easy access to Tcl/Tk. The powerpoint solution was also non-optimal since power point does a poor job with these sorts of tasks.
So, I figured this might be a great way to showcase the power of Lua (with the LuaCairo binding). I ended up writing this railroad diagram generator. Note that this railroad diagram "generator" requires you to fully specify your "railroads", which direction they are flowing and all the "entrances" and "exits", so it isn't particularly easy to use at the moment (ideally it would just parse BNF to generate the diagrams). It also has a fair number of hacks that I still need to work out before I really "publish" this, but the above picture is my first working rail road diagram.
This diagram is for the "chunk" production described in the Lua Manual. Here is the equivalent BNF production:
chunk ::= {stat [`;´]} [laststat [`;´]]
Note that the yellow in the diagram is to demarcate "terminals" in the syntax. I hope to later on do the complete syntax with links in the grammar to the other diagrams (and perhaps have the "terminals" link to the description of what they mean in the manual?

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home