- Syntax diagram
Syntax diagrams (or railroad diagrams) are a way to represent a
formal grammar . They represent a graphical alternative toBackus-Naur Form orEBNF . Early books using syntax diagrams include the "Pascal User Manual" written by Niklaus Wirth [http://www.standardpascal.org/The_Programming_Language_Pascal_1973.pdf Niklaus Wirth: "The Programming Language Pascal." (July 1973)] ] (diagrams start at page 47) and the Burroughs CANDE manual http://bitsavers.org/pdf/burroughs/B6500_6700/5000318_B6700_CANDE_Oct72.pdf] . In the compilation field, textual representations like BNF or its variants are usually preferred. BNF is well understood by compiler writers and compilers, but is not well understood by most users of languages. Railroad diagrams are more readily understood by most people. Some of the popularity of theJSON data interchange format is due to its representation in railroad diagrams.Principle
The representation of a grammar is made of a set of syntax diagrams. Each diagram defines a non-terminal. There is a main diagram which defines the language in the following way: to belong to the language, a word must describe a path in the main diagram.
Each diagram has an entry point and an end point. The diagram describes possibles paths between these two points by going through other nonterminals and terminals. Terminals are represented by round boxes while nonterminals are represented by square boxes.
Example
We use arithmetic expressions as an example. First we provide a simplified BNF grammar:
This grammar can also be expressed in
EBNF :One possible set of syntax diagrams for this grammar is:
ee also
*
Extended Backus-Naur form (EBNF)References
External links
* [http://www.json.org/ JSON website including syntax diagrams]
* [http://www-cgi.uni-regensburg.de/~brf09510/syntax.html Automatic generator of syntax diagrams]
* [http://www-cgi.uni-regensburg.de/~brf09510/syntax/lazyebnf.ebnf.html Syntax diagrams of BNF]
* [http://dotnet.jku.at/applications/Visualizer/ Generator from EBNF]
* [http://www.informatik.uni-freiburg.de/~thiemann/haskell/ebnf2ps/ From EBNF to a postscript file wit the diagrams]
Wikimedia Foundation. 2010.