Version 1 of Generating Syntax Diagrams Using Tk

Updated 2008-10-11 00:13:34 by drh

Tcl/Tk saves the day!

SQLite users wanted syntax diagrams instead of BNF to describe the SQL language. Syntax diagrams look something like this:

http://www.sqlite.org/draft/images/syntax/create-table-stmt.gif

The question become: how does one generate diagrams? A quick Tcl/Tk script did the job for me nicely. A high-level description of each diagram (in the form of a nested Tcl list, though really more of a lisp predicate) is entered and a Tk script renders the diagram on a canvas widget. The postscript method of the canvas widget is then used to create a postscript file of the diagram. Finally, the "convert" utility of ImageMagick is invoked (via the "exec" command) to convert the postscript into an anti-aliased GIF at the appropriate resolution.

Since the diagrams have gone up on the SQLite website, there have been multiple questions of "how did you do that?" So in answer, I present the script that does the syntax diagram generation for SQLite. (The link below is directly into the Fossil repository for the SQLite documention. Click on the "view" link to see the actual text of the script.)

http://www.sqlite.org/docsrc/finfo?name=art/syntax/bubble-generator.tcl


enter categories here