Content deleted Content added
Gregg-Irwin (talk | contribs) m Move closing text above diagram and refine. |
Undid revision 1293116503 by Jmason37 (talk) spam; we do not need two links to the same site |
||
(18 intermediate revisions by 12 users not shown) | |||
Line 1:
{{Short description|Visual description of context-free grammar}}
'''Syntax diagrams''' (or '''railroad diagrams''') are a way to represent a [[context-free grammar]]. They represent a graphical alternative to [[Backus–Naur form]], [[EBNF]]
== Principle
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.
Line 9 ⟶ 10:
== Example ==
We use arithmetic expressions as an example, in various grammar formats.
BNF:
Line 34 ⟶ 35:
ABNF:
<syntaxhighlight lang="abnf" highlight="6">
expression = term ["+" expression]
term = factor ["*" term]
Line 42 ⟶ 43:
DIGIT = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
</syntaxhighlight>
[[
<syntaxhighlight lang="Red" highlight="7">
Red [Title: "Parse Dialect"]
expression: [term opt ["+" expression]]
term: [factor opt ["*" term]]
Line 53 ⟶ 55:
digit: ["0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"]
</syntaxhighlight>
One possible syntax diagram for the example grammars is below.
▲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 is a [[metalanguage]].
[[Image:Syntax-diagram-example.png|"Railroad" syntax diagram]]
==See also==
Line 75:
* [https://karmin.ch/ebnf/index EBNF Parser & Renderer]
* [https://www.sqlite.org/docsrc/finfo?name=art/syntax/bubble-generator.tcl SQLite syntax diagram generator for SQL]
* [https://www.bottlecaps.de/rr Online Railroad Diagram Generator]
* [https://www.yorku.ca/jmason/asdgram.htm Augmented Syntax Diagram (ASD) grammars]
* [http://www.asd-networks.com (ASD) '''Augmented''' Syntax Diagram Application Demo Site ]
|