HOME

TheInfoList



OR:

Syntax diagrams (or railroad diagrams) are a way to represent a context-free grammar. They represent a graphical alternative to Backus–Naur form, EBNF,
Augmented Backus–Naur form In computer science, augmented Backus–Naur form (ABNF) is a metalanguage based on Backus–Naur form (BNF), but consisting of its own syntax and derivation rules. The motive principle for ABNF is to describe a formal system of a language to be use ...
, and other text-based grammars as metalanguages. Early books using syntax diagrams include the "Pascal User Manual" written by
Niklaus Wirth Niklaus Emil Wirth (born 15 February 1934) is a Swiss computer scientist. He has designed several programming languages, including Pascal, and pioneered several classic topics in software engineering. In 1984, he won the Turing Award, generally ...
Niklaus Wirth: ''The Programming Language Pascal.'' (July 1973)
/ref> (diagrams start at page 47) and the Burroughs
CANDE Cande may refer to: * Candé, a commune in western France * Čande, a village in Bosnia and Herzegovina * CANDE, a command-line shell * Candé, a surname: ** Baciro Candé, Guinea-Bissauan footballer ** Braima Candé, Portuguese footballer ** Mam ...
Manual.Burroughs B6700/B7700 ''Command AND Edit (CANDE) Language: Information Manual''
/ref> In the compilation field, textual representations like BNF or its variants are usually preferred. BNF is text-based, and used by compiler writers and parser generators. Railroad diagrams are visual, and may be more readily understood by laypeople, sometimes incorporated into graphic design. The canonical source defining the JSON data interchange format provides yet another example of a popular modern usage of these diagrams.


Principle of syntax diagrams

The representation of a grammar is a set of syntax diagrams. Each diagram defines a "nonterminal" stage in a process. 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 possible paths between these two points by going through other nonterminals and terminals. Historically, terminals have been represented by round boxes and nonterminals by rectangular boxes but there is no official standard.


Example

We use arithmetic expressions as an example, in various grammar formats. BNF: ::= , "+" ::= , "*" ::= , , "(" ")" ::= "x" , "y" , "z" ::= , ::= "0" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" EBNF: expression = term , "+" , expression term = factor , "*" , term factor = constant , variable , "(" , expression , ")"; variable = "x" , "y" , "z"; constant = digit , ; digit = "0" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9"; ABNF: expression = term +" expressionterm = factor *" termfactor = constant / variable / "(" expression ")" variable = "x" / "y" / "z" constant = 1*digit DIGIT = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" Note that ABNF also supports ranges, e.g. , but it is not used here for consistency with the other examples.
Red (programming language) Red is a programming language designed to overcome the limitations of the programming language Rebol. Red was introduced in 2011 by Nenad Rakočević, and is both an imperative and functional programming language. Its syntax and general usage ov ...
Parse Dialect: Red itle: "Parse Dialect"expression: erm_opt_["+"_expression term:_______ erm_opt_["+"_expression term:_______[factor_opt_["*"_term">+"_expression.html"_;"title="erm_opt_["+"_expression">erm_opt_["+"_expression term:_______[factor_opt_["*"_term factor:_____[constant_.html" ;"title="actor_opt_ erm_opt_["+"_expression term:_______[factor_opt_["*"_term">+"_expression.html"_;"title="erm_opt_["+"_expression">erm_opt_["+"_expression term:_______[factor_opt_["*"_term factor:_____[constant_">_variable_.html" ;"title="*"_term.html" ;"title="+"_expression.html" ;"title="erm opt erm_opt_["+"_expression term:_______[factor_opt_["*"_term">+"_expression.html"_;"title="erm_opt_["+"_expression">erm_opt_["+"_expression term:_______[factor_opt_["*"_term factor:_____[constant_">_variable_">_"("_expression_")"variable:___["x"_.html" ;"title="+" expression">erm opt term:_______[factor_opt_["*"_term">+"_expression.html"_;"title="erm_opt_["+"_expression">erm_opt_["+"_expression term:_______[factor_opt_["*"_term factor:_____[constant_">_variable_">_"("_expression_")"variable:___["x"_">_"y"_.html" ;"title="+" expression term: [factor opt ["*" term">+"_expression.html" ;"title="erm opt ["+" expression">erm opt ["+" expression term: [factor opt ["*" term factor: [constant "> variable "> "(" expression ")"variable: ["x" "> "y" "> "z"constant: [some digitdigit: ["0" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" Note that this format also supports ranges, e.g. , but it is not used here for consistency with the other examples. One possible syntax diagram for the example grammars is below. Note that while the syntax for the text-based grammars differs, the syntax diagram for all of them can be the same because it is a metalanguage.


See also

* Recursive transition network * Extended Backus–Naur form (EBNF)


References

{{reflist Note: the first link is sometimes blocked by the server outside of its domain, but it is available o
archive.org
The file was also mirrored a
standardpascal.org


External links


JSON website including syntax diagrams

Generator from EBNF

From EBNF to a postscript file with the diagrams

EBNF Parser & Renderer

SQLite syntax diagram generator for SQL

Online Railroad Diagram Generator



(ASD) Augmented Syntax Diagram Application Demo Site

SRFB Syntax Diagram representation by Function Basis + svg generation
Formal languages Diagrams